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.