Running some bash scripts written on a Windows Machine resulted in the following error:
-bash: ./shell_script.sh: /bin/bash^M: bad interpreter: No such file or directory
I initially resolved this issue on the Linux machine it was intended to run with the following command:
sed -i -e 's/\r$//' shell_script.sh
However, I recently discovered a more practical command that’s easier to remember and use: dos2unix. This tool runs also runs some additional conversions to ensure compatibility. Here’s an example of how to use it:
dos2unix shell_script.sh
I’ve now added dos2unix to my standard Linux setup/deployment.