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.

Comments (1) -

  • Prashant kumar

    1/30/2022 4:18:50 PM | Reply

    Hi Donovan, I am very glad that you have written the post about this error. I had also found this. I used dos2unix command line to solve the problem.

Add comment