Linux Shell Troubleshooting
A guide to troubleshooting common issues in the Linux shell, including solutions for common errors.
bad interpreter: No such file or directory
When you encounter the error /bin/sh^M: bad interpreter: No such file or directory
while trying to execute a script, it is likely caused by the script being created in Windows and then executed in Linux. Windows uses CR
LF
(\r\n
) as the line ending, while Linux uses just LF
(\n
). The \r
(carriage return) character is not recognized by Linux, leading to this error.
To fix this issue, you can remove the carriage return characters from the script using the following command:
sed -i -e 's/\r$//' scriptname.sh
This command will modify the script in place, removing the \r
characters and leaving only the \n
characters as line endings.
For more information, you can refer to the Stack Overflow discussion.