Friday, June 24, 2016

/bin/sh^M: bad interpreter: No such file or directory

Very simple thing but sometimes it will bother you a lot.

I tried to run a shell script  “” but it was giving me following error

/bin/sh^M: bad interpreter: No such file or directory

Solution was:

  Need to execute following script to clean up windows formatting things (spaces) and make it pure linux formated script. after executing following command (with the script) it worked perfectly.see in below screenshot.

$sed -i -e 's/\r$//'

Explanation:  The ^M is a carriage return character. Linux uses the line feed character to mark the end of a line, whereas Windows uses the two-character sequence CR LF. Your file has Windows line endings, which is confusing Linux. Remove the spurious CR characters using  sed -i -e 's/\r$//'

Please see in below image.


JNahin said...

OMG! You are a life saver, thanks a kabillion!

JNahin said...

OMG! You are my hero!

Anonymous said...

set fileformat=unix execute this inside the script. it will allow you to execute the script.