Sunday, December 25, 2016

/bin/sh^M : bad interpreter - Error while executing Shell script

      Sometimes we may encounter with "./configure : /bin/sh^M : bad interpreter" error while executing shell script on UNIX machines.Unix uses different line feeds and carriage returns so can't read the file you created on Windows. Hence it is seeing ^M as an illegal character. We can solve this as follows:

Solution-1 : To fix this, open your script with vi editor and enter in vi command mode (key ESC), then type this:

:set fileformat=unix

Finally save it :x! (or) :wq!

Solution-2 : If you want to write a file on Windows and then port over, make sure your editor is set to create files in UNIX format.

In notepad++ in the bottom right of the screen it tells you the document format. By default it will say Dos\Windows, To change it go to

settings --> preferences --> New Document tab --> select the Format as Unix(LF) and then close and create a new document.

No comments:

Post a Comment

back to top