Bash, Bad Interpreter

I recently came across:

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

When trying to run a bash script that someone else had edited. This most commonly happens on UNIX systems if the file has been edited on MS-DOS or Mac. The cure for this is to run a simple perl script:

1
2
#!/usr/bin/perl -pi
s/\n/\r\n/;

Save as unix2dos.pl, chmod +x unix2dos.pl and then run like:

./unix2dos.pl filetoconvert.txt

Simples!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>