bin/bash^M: bad interpreter: no such file or directory
I got this error recently when trying to execute a bash script in Linux.
bin/bash^M: bad interpreter: no such file or directory
The problem turned out to be the fact that I downloaded it to a windows machine before copying it to the Linux box. When I downloaded it windows added a number of Windows Carriage Returns at the end of each line. Why? Don’t ask me!
After a bit of Googling I found a number of posts that recommended I use dos2unix to convert it into unix file format. Unfortunately I didn’t have this on my system. So instead I used the following command.
tr -d '\r' < inputfile > outputfile






Thanks John.. 3 years later I still find your post about removing the escape character is relevant..
@Fergal
^^ oh, should have said, it needs to be in ~/.vimrc
Here you go (it’s vim only, not vi)
nmap xr :silent! %s/\r//gc
Yeah Fergal, that’d be great. If you send it on I can attach it to this post for anyone else who might find it useful.
It’s the belt an braces approach of windows, line-terminating with carriage return & line feed chars…
Programmers nightmare.. I have a vim script that auto strips these when you open a file if you want it.