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

This happens when the bash script has windows line feed and carriage return.

This can be fixed with a oneliner:

sed 's/\r//' filename > filename.tmp && mv filename.tmp filename