Dev

"bin/bash^M: bad interpreter" happens when we run shell file.

Share this for your friends.

bin/bash^M: bad interpreter happens when we run shell file.

"bin/bash^M: bad interpreter" happens when we run shell file.
bin/bash^M: bad interpreter: No such file or directory
This article introduce why this error happens and how to avoid this error.


Cause

According to the error message, it seems that the error is caused by wrong file path.
But it is not root cause.

bin/bash^M: bad interpreter: No such file or directory

Root cause is line feed code.
Line feed code of Windows is CRLF \r\n.
Linux one is LF \r\n.
If shell file is created with CRLF \r\n, it occurs error on linux environment.

参考:
/bin/bash^M: bad interpreter: No such file or directory


How to avoid the error

Replace Windows line feed code CRLF \r\n with Linux line feed code LF \n.
Text editor and regular expressionis are helpful to replace.


Finally

  • Reason of "bin/bash^M: bad interpreter" error is line feed code.
  • In order to avoid the error, you can replace \r\n with \n.



Share this for your friends.

If you felt this article is useful, please share.

にほんブログ村 IT技術ブログへ

-Dev
-, ,

© 2024 ITips