1

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?

2
  • 2
    Please take a look at How to create a Minimal, Complete, and Verifiable example.
    – Cyrus
    Commented Apr 4, 2015 at 16:15
  • 1
    Yes, bash has implemented additional commands, and is a superset of sh (or dash). If your script uses bash-specific commands (some call them "bashisms") then you must use bash to execute the script. Commented Apr 4, 2015 at 16:32

1 Answer 1

2

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 .