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

Home > Search
  by

This error appears when attempting to run a Bash shell script.

~]# example.sh
-bash: ./example.sh: bin/bash^M: bad interpreter: No such file or directory

 

This typically occurs when a bash script is copied from one machine to another machine, which causes carriage returns to be added to the ends of the lines in the script. The following command will remove the carriage returns from the script.

sed -i -e 's/\r$//' example.sh

 

If the above command works, this may be only a temporary fix, as you would need to do the same the next time the file is moved from a DOS/Windows machine to a Unix/Linux machine. To prevent this problem from continuing, open the script in vi, and set the file format to Unix.

:set fileformat=unix

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments