Linux

Linux scripting: how to fix “bad interpreter” error

During bash script execution on Linux, it might happen to face the following error:

[root@localhost nullalo]# ./configure
bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory

This often happens when the executed script (in the above example, the “configure” file) has been edited on a Windows OS with an editor who saved it with DOS (CR + LF) line endings instead of Unix (LF) ones.
The quickest way to solve the problem is to run one of these commands directly from Linux (obviously “configure” should be replaced with the name of your file):

sed -i 's/\r//' configure
perl -i -pe's/\r$//;' configure

Also, if you use vi or vim as editor or Linux, you can run the following commands (with the ESC key to enter editor command mode):

:set fileformat=unix
:x! (or :wq!)

which, respectively, set the file format and save it, quitting the editor.

Previous post

How to type accents, symbols and emoji on Mac

Next post

Linux: how to change default editor

Fulvio Sicurezza

Fulvio Sicurezza

No Comment

Leave a reply

Your email address will not be published. Required fields are marked *