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

This is caused by additional carriage returns within your script. In Windows the end of a line is denoted by CRLF (Carriage-Return, Line-Feed). In Unix-like systems, the end of a line is donated by a single LF. This means when you try to run your script, every line has an extra carriage return which in turn causes issues.

One solution to this is to strip out the extra carriage returns, which can be done via a simple sed command.
sed -i 's/{ctrl-v}{ctrl-m}//g' [file]

About the Author


R Donato

Rick Donato is the Founder and Chief Editor of He currently works as an SDN/NFV Solutions Architect and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001