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  “daily_full_expdp_backup.sh” 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$//' daily_full_expdp_backup.sh

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.