Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

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 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

1 Answer 1

up vote 4 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

 
discard

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.