I had the below script working in a linux machine.

page="$(curl http://www.google.com/| grep "title")"
if [ -z "$page" ]; then
echo "Empty page"
echo "Valid page"

When am running in another machine, I am getting the error syntax error: unexpected end of file. Why am getting this error?

  • 1
    What are the machines? You have to watch for differences in the various shells. – slm Feb 8 '14 at 3:48

You probably have invisible CR characters at the end of your lines (like when the file is in Microsoft format where the lines are terminated by the CRLF sequence of characters instead of just LF).

Then, the shell complains that it reaches the end of the script file without finding a then following the if (there's just a then<CR>).

Use dos2unix or d2u, or issue a :set ff=unix in vim to fix your script file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.