開発

"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" 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.


コチラもオススメ

KRSW

駆け出し機械学習エンジニア。機械学習、DB、WEBと浅く広い感じ。 Junior machine learning engineer. Not a specialist but a generalist who knows DB, WEB too.

If you felt this article is useful, please share.

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

-開発
-, ,

Translate »

Copyright© ITips , 2020 All Rights Reserved.