Generally,the value of environment variable SHELL
is /bin/bash, it means normal shell environment is Bash,However,the /bin/sh is the link of Dash, what is the Dash effect?
Another question: Although our shell environment is bash, why sometimes it will go wrong because of dash?
General comment about
sh
The shell
sh
is a symbolic link todash
, which is a shell with a very light foot-print. It means that it can work quickly and will not use much memory. But the built-in commands are few, simple and have different syntax compared to more advanced shells (for examplebash
).Both shells (
sh
andbash
) are useful but for different purposes.How to make a shellscript run by
bash
If you run a text file with commands, a shellscript, you can force it to run by a certain shell. Otherwise it may default to a shell, that does does not work as intended, for example because some built-in command does not exist or the syntax for a built-in command is different.
So in order to make a shellscript run with
bash
, you can force itby calling it from
bash
by writing a line at the top of the file, a first line with the content
This is called 'shebang'. The shebang can point to other shells too, for example
sh
orcsh
but also other programs, for examplepython
orbc
. If you make the shellscript file executableyou can run it with the following command
and it will be executed by the shell or other program in the shebang.
They main point is that
bash
is meant for interactive use,dash
is used for system scripts.bash
comes with whole lot of features, among which is line editing. You have specific shortcuts to delete a word, jump to beginning of line, etc. This is convenient for writing commands interactively. However that comes at a price of performance and boot up times.dash
on the other hand is meant for writing system scripts that are fast and portable, thus helping keep the boot times short, and on Ubuntu it is compiled without line editing, even withoutvi
editing mode. Thus, it has less overhead.bash
is capable of running exactly same scripts/bin/dash
runs ( if they are written with portable syntax, of course ), butdash
is just faster at doing these same things.Note, of course, that users are free to change their login shell via
chsh
command, and you don't have to stick withbash
if that's not what you prefer.