I'm using Ubuntu 14.04.02 32bit.

On doing some shell programming, I found out that running the script through the sh command sometimes cause errors.

Is it because the sh command is invoking the dash shell instead of #!/bin/bash ?

I'm having trouble with the select command.

It goes well when I execute it by ./scriptName.sh, but sh scriptName.sh reports syntax errors. Why is this happening?


1 Answer 1


If your script uses bash syntax, it must start with #!/bin/bash. If you execute it with /path/to/script then all will be well. If you call the interpreter (the shell) explicitly, then you need to call the correct one, i.e. bash, not sh or perl or whatever.

There are several variants of sh. Bash is one. Dash is another. Compared with bash, dash has fewer features but is faster and uses less memory. This is why Ubuntu chose to use dash as sh; if you need bash's extra features then n you should call it explicitly anyway.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .