My script will not run in Bash if I edit on Windows!


When I try and run a Bash script in WSL I get the following warning:

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


From WSL run the following command on the file:

sed -i -e 's/\r$//'

If you are using Visual Studio Code you can simply change the line ending by clicking CRLF in the lower right hand corner of the screen and change the LF and save the file.



Developing on a Windows based systems will use different line ending than are expected by Linux based system. This is what is causing the error. Correct the line ending and the script should run as expected.

Add comment