What is the difference between bash and sh?
Solution 1:
bash
is a superset of sh
ie. everything you can do in sh
you can do in bash
.
Bash has more features (branching, builtins, arrays) making script easier to write. Some later *nix'es have /bin/sh
as a link to /bin/bash
For a full explanation of what here's a tutorial
Solution 2:
Traditionally, /bin/sh would have been the original Bourne shell, which has no history or command-line editing, and no job control.
For about the last 15 years or so, most Unixes have had the POSIX shell installed, or at least ksh or bash (which are very nearly POSIX-like), but still have the more limited shell in /bin/sh
The reason for that is so that older shell scripts which expect the older sh
command will still work.
Since characters like {
, }
and !
have special meaning to bash, it's possible that an older shell script using those characters (without escaping them) could fail.
(The Bourne shell would take !!{1,2}
literally, whereas bash would interpret that as a repeat of the previous command (!!
) followed by a brace-expansion).
On Linux though, the sh
command is almost always just a link to bash
, with all the same features.