I can't normally run sh scripts. It's confusing. I set the permissions to 777 and +x so it should work with the 'sh' command, right...

But it's working very strange. For example this scripts works ok:

echo "hello"

it prints "hello" with no errors. But this script:

#!/bin/bash
for i in `seq 1 5`; do 
    echo $i
done

...outputs this error:

Syntax error: end of file unexpected (expecting "done")

Is there something wrong with that loop?

  • How do you run the above script? The loop it looks ok. – Radu Rădeanu Sep 3 '13 at 8:32
  • I run it with the sh command: sh script.sh – user568021 Sep 3 '13 at 8:36
  • You defined bash and not sh for your script, so run it with bash script.sh – Frantique Sep 3 '13 at 8:37
  • 2
    Are you sure that you have the last line (done) in your original script (script.sh)? – Radu Rădeanu Sep 3 '13 at 8:38
  • @Frantique This problem does nothing have to do with your observation. – Radu Rădeanu Sep 3 '13 at 8:41
up vote 7 down vote accepted

The problem it is, that you probably made a Ctrl+C Ctrl+V from a website, and the end-of-line char there was something strange, not printable character. (You can make it visible by dumping to hex the file.)

Please open your file in an editor, and retype everything manually, or at least remove the last eol characters, save your work, and try again.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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