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

If you’ve ever seen this error when trying to execute a script on a Linux system, you’re not alone. Fortunately, there are a couple of easy solutions.

This error is caused when bash runs into an invisible character that it doesn’t like. The most common cause is when a file was edited or created on a Windows PC. Even programs like Notepad will insert unseen characters that the bash shell can’t interpret.

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

Here are two solutions to quickly remedy the problem:

Option 1. Use the following sed command on the file:

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

Option 2. Install dos2unix and run it on the file. Use your system’s package manager; the following example works on Ubuntu:

sudo apt install dos2unix
dos2unix filename

Either option works and you should now be able to execute the file.

Leave a Comment

Your email address will not be published. Required fields are marked *