Problem:
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
Solution:
From WSL run the following command on the file:
sed -i -e 's/\r$//' badfile.sh
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.
Explanation:
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.