/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 a fan of innovative devices?

Caronte Consulting designs and realized hardware and software systems for Industry 4.0, equipped with sophisticated and effective Artificial Intelligence.

Our devices are tailor-made according to the customer’s needs and create a complete automated industry, optimizing production and saving raw materials and energy consumption.