How to fix a /bin/sh^M : bad interpreter error

bash tips Unix vi vim

Sometimes if you execute a script via the CLI you get following error /bin/sh^M : bad interpreter.

This is because of the line endings in your file are DOS line endings. The clue is the ^M. What you need to do is just re-save the file using Unix line endings.

To fix this, open your script with vi or vim and enter in vi command mode (key ESC), then type this:

:set fileformat=unix

Finally save it

:x! or :wq!


comments powered by Disqus