How to solve /bin/bash^M: bad interpreter - Caronte Consulting
How To bin bash bad interpreter Cover

How to solve /bin/bash^M: bad interpreter

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

HOW TO RUIN YOUR MORNING

You wake up a morning, start your Linux terminal and run your script … a strange message appears:

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

Basically, the error message says that there is no file named /bin/bash^M. Ok, but there is no ^M in your script!

^M is a character used by Windows to mark the end of a line (so it is a carriage return) and that matches the CR character. Basically we are faced with a line termination used by Windows in a Linux script, of course this is confusing.

This often happens when you copy and paste from Windows into an SSH window (eg when connecting from Windows to your Raspberry Pi).

To remove the spurious CR characters, simply execute the command:

sed -i -e ‘s/\r$//’ nomefile.sh

ARE YOU INTERESTED IN OUR PRODUCTS?

OUR SERVICES ARE YOU INTRIGATING?

DO YOU WANT TO MAKE AN INNOVATIVE DEVICE?

Share your thoughts