Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question
2  
Please take a look at How to create a Minimal, Complete, and Verifiable example. –  Cyrus Apr 4 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. –  glenn jackman Apr 4 at 16:32

1 Answer 1

up vote 1 down vote accepted

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.

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.