Linux: how to fix error: /usr/bin/sh^M: bad interpreter: No such file or directory


Example error:

[root@tutorialspots ~]# /home/videos/1.sh 1 2 3
-bash: /home/videos/1.sh: /usr/bin/sh^M: bad interpreter: No such file or directory

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. You can do it with the following command:

sed -i -e 's/\r$//' /home/videos/1.sh

Leave a Reply