Bash syntax error: unexpected end of file

Bash syntax error: unexpected end of file

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

Another thing to check (just occured to me):

  • terminate bodies of single-line functions with semicolon

I.e. this innocent-looking snippet will cause the same error:

die () { test -n [email protected] && echo [email protected]; exit 1 }

To make the dumb parser happy:

die () { test -n [email protected] && echo [email protected]; exit 1; }

Bash syntax error: unexpected end of file

i also just got this error message by using the wrong syntax in an if clause

  • else if (syntax error: unexpected end of file)
  • elif (correct syntax)

i debugged it by commenting bits out until it worked

Leave a Reply

Your email address will not be published.