Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

for i in `seq 1 5`; do 
    echo $i

...outputs this error:

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

Is there something wrong with that loop?

share|improve this question
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 – user568021 Sep 3 '13 at 8:36
You defined bash and not sh for your script, so run it with bash – Frantique Sep 3 '13 at 8:37
Are you sure that you have the last line (done) in your original script ( – 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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