Bash script: bad interpreter

Could the script be using Dos newlines?

Try running dos2unix on it.


The first line, #!/bin/bash, tells Linux where to find the interpreter. The script should also be executable with chmod +x script.sh, which it appears you did.

It is highly likely that you created this file with a windows editor, which will place a <cr><lf> at the end of each line. This is the standard under dos / windows. OS X will place a <cr> at the end of each line. However, under Unix / Linux, the standard is to just put a <lf> at the end of the line.

Linux is now looking for a file called /bin/bash<cr> to interpret the file, where <cr> is a carriage return character, which is a valid file character under Linux. Such a file doesn't exist. Hence the error.

Solution: Edit the file with an editor on Linux and get rid of the extra <cr>. One tool that usually works when the file is edited on Windows is dos2unix.