Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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 have the following simple script:

echo "Bash version ${BASH_VERSION}..."
for i in {1..99..2}
        echo $i

Output in case I run with sh

Bash version ...

Output in case I run with bash

Bash version 4.2.25(1)-release...

I have two queries:

  1. If I have written a shabang line specifying shell, shouldn't it run with bash whether I use sh or bash

  2. I understand that $BASH_VERSION is not recognized by sh but what is the problem with for loop? Why isn't printing the numbers?

share|improve this question
up vote 16 down vote accepted

sh, the Bourne shell, is old. Its behaviour is specified by the POSIX standard. If you want new behaviour, you use bash, the Bourne Again shell, which gets new features added to it all the time. On many systems, sh is just bash, and bash turns on a compatibility mode when run under that name. On Ubuntu, sh is dash, the Debian Almquist shell.

The brace expansion is a relatively new feature, and would not be available in older bashes as well. It certainly shouldn't be in sh.

The shebang line is only respected if you call the script as an executable:


I can give a script any shebang and still have it open in Python by running:


See these excellent questions on Unix & Linux:

share|improve this answer

SH is stupid. It can not do anything.

It only knows the most basic commands. It does not do anything else.

It can not understand {1..99} as a numeric value. It understands it as a string.

SH/Dash is not developed. It is meant to be an emergency prompt for DIRE circumstances (in interactive mode. Otherwise, it's a really good thing for scripting.).

Bash is recommended as it can do everything SH can, as well as the newest in customization and powerful features.

In answer to #1, the #! is only parsed if the program is called directly. (as in, ./

share|improve this answer
"It is meant to be an emergency prompt for DIRE circumstances." dash, which as you say provides sh in Ubuntu, isn't present mainly "to be an emergency prompt for DIRE circumstances" but instead so the system can run, and start, fast. In this way, dash is well suited to use in a modern OS, but what it's well suited for is as a low-profile, fast shell for scripting--particularly, running system scripts while booting a big, complex, modern OS, with minimal performance overhead. – Eliah Kagan Aug 30 '14 at 7:51
@EliahKagan You really only use SH if something when terribly wrong. – Kaz Wolfe Aug 30 '14 at 7:52
You use sh pretty constantly, and particularly intensively as Ubuntu boots. It's mainly important for its automated scripting uses, and that is a very important use case in Ubuntu. (If you were to remove the /bin/sh symlink--so that, in effect, there would be "no SH"--things would go terribly wrong: Ubuntu could not boot up into a usable state.) – Eliah Kagan Aug 30 '14 at 7:54
@EliahKagan When did you last use SH as your preferred terminal? I know you use it to script, but when do you actually use it in interactive mode? – Kaz Wolfe Aug 30 '14 at 7:56
Yesterday, to check how portable a command was. But your point that interactive use of dash is rare is valid. (And anyway, the context of my interactive use was still scripting-oriented.) ....But "use" does not mean "interactive use," and more importantly, the use case in this question is not an interactive one! – Eliah Kagan Aug 30 '14 at 7:59

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.