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

DOS uses a carriage return (^M) with a line feed therefore linux system confused and thinks the script should be executed by /bin/bash^M which doesn’t exist.


Option 1:

Install dos2unix and convert the file

dos2unix myscript.sh

Option 2:

vi and vim will convert line endings when you specify the file format.

vi myscript.sh

Hit ESC to enter command mode where you can set the format and save your changes.

:set fileformat=unix


Option 3:

sed is handy for cleaning up things like this from the command line.

sed -i 's/r//' myscript.sh