Bash syntax error: unexpected end of file

markcruz picture markcruz · Jun 16, 2011 · Viewed 238k times · Source

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

Answer

clyfish picture clyfish · Jun 16, 2011

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