Bash syntax error: unexpected end of file

bashsyntax

Forgive me for this is a very simple script in Bash. Here's the code:

#!/bin/bash
# june 2011

if [ $# -lt 3 -o $# -gt 3 ]; then
   echo "Error... Usage: $0 host database username"
   exit 0
fi

after running sh file.sh:

syntax error: unexpected end of file

Best Answer

I think file.sh is with CRLF line terminators.

run

dos2unix file.sh

then the problem will be fixed.

You can install dos2unix in ubuntu with this:

sudo apt-get install dos2unix