DOS File Format Error

If you use Cygwin to write shell scripts on Windows, chances are you'll accidentally create a shell script in DOS format. When this happens Bash will flag a syntax error in the script. Usually it looks like a string has not been terminated, something similar to this:

./myscript.sh: line 54: syntax error: unexpected end of file

If you use Vi on the *.sh file it will show you the syntax, but everything looks fine. What's wrong?

Bash isn't able to figure out how to deal with the \r\n at the end of each line. To this this just use dos2unix:

dos2unix myscript.sh

One Line Function Error

It's also possible that you have a one line function that isn't terminated properly, i.e., it's missing a trailing semicolon:

redmsg() { echo -e "\033[34m\033[41m$@\033\(B\033[m" }

Add the semicolon:

redmsg() { echo -e "\033[34m\033[41m$@\033\(B\033[m"; }