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

I was getting the following error when trying to execute a shell script in CentOS:

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

The problem was that I had created the script in Notepad on a Windows computer, which inserted invisible characters that cause this error. The characters weren’t visible in Notepad or vi, but here’s the script I used to quickly get rid of the invisible characters:

sed -i s/{ctrl+v}{ctrl+m}// filename