Thursday, October 13, 2016

/bin/sh^M: bad interpreter Errors

This is just to remind me of the errors that I experienced alot which is : /bin/sh^M: bad interpreter Errors , mostly I experienced this when running .sh files which is edited on windows (using notepad, etc) and then upload it to Centos/Ubuntu and run it.


The ^M is a carriage return character. Linux uses the line feed character to mark the end of a line, meanwhile Windows uses the two-character sequence CR LF. my file has windows endings which confused linux.

To fix it we just need to replace windows line ending character which you can use using any linux text editor like vim or nano, but there's a simple command which you can use to do this

sed -i -e 's/\r$//' your_sh_file.sh

References

  • http://askubuntu.com/questions/304999/not-able-to-execute-a-sh-file-bin-bashm-bad-interpreter

1 comment :