Home > Linux, VMware > bin/bash^M: bad interpreter: no such file or directory

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

December 29th, 2009 Leave a comment Go to comments

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

Categories: Linux, VMware Tags:
  1. September 19th, 2012 at 02:29 | #1

    Thanks John.. 3 years later I still find your post about removing the escape character is relevant..

  2. Fergal
    January 4th, 2010 at 11:56 | #2

    @Fergal
    ^^ oh, should have said, it needs to be in ~/.vimrc

  3. Fergal
    January 4th, 2010 at 11:51 | #3

    Here you go (it’s vim only, not vi)

    nmap xr :silent! %s/\r//gc

  4. January 4th, 2010 at 10:07 | #4

    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.

  5. Fergal
    January 4th, 2010 at 09:29 | #5

    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.

  1. No trackbacks yet.