By Rebecca Sobol
July 29, 2009
A reoccurring topic on Debian lists is the use of dash (Debian
Almquist Shell) as opposed to bash (GNU Bourne-Again Shell).
Currently /bin/sh defaults to bash on a Debian system,
but some would like the default to be
dash.
Ubuntu made this switch three years
ago, with the release of Ubuntu 6.10. Note that the default login shell
remains bash, only the default /bin/sh used in shell
scripts has been changed. Why did Ubuntu make this change?
The major reason to switch the default shell was
efficiency. bash is an excellent full-featured shell appropriate
for interactive use; indeed, it is still the default login
shell. However, it is rather large and slow to start up and operate by
comparison with dash. A large number of shell instances are
started as part of the Ubuntu boot process. Rather than change each of
them individually to run explicitly under /bin/dash, a change
which would require significant ongoing maintenance and which would be
liable to regress if not paid close attention, the Ubuntu core
development team felt that it was best simply to change the default
shell. The boot speed improvements in Ubuntu 6.10 were often incorrectly
attributed to Upstart, which is a fine platform for future development of
the init system but in Ubuntu 6.10 was primarily running in System V
compatibility mode with only small behavioural changes. These
improvements were in fact largely due to the changed /bin/sh.
The Debian EeePC project also notes that dash provides
faster boot times. So why hasn't Debian already made this switch? In
fact this was a release goal for
Lenny.
Part of the problem is "bashisms" - use of non-standard bash features -
in shell scripts. There is a lengthy list of bugs tagged
with goal-dash that contain bashisms. These are being worked on,
package by package. While some users report that they have already made
the switch without problems, others will find many of their user scripts
will have bashisms.
One can use
checkbashisms (
man
page) to look for bashisms, but for users with lots of scripts using
/bin/sh this could be a long and painful process.
Here's a sample of
checkbashisms output for the package
apertium:
checkbashisms' output:
> possible bashism in ./usr/bin/apertium-preprocess-corpus-lextor line 47
> ('((' should be '$(('): if ((length(w)>0) && (index(w,"^")>0)) {
> possible bashism in ./usr/bin/apertium line 9 ('function' is useless):
> function message
Examples of bashisms include use of $RANDOM, the select,
let, and source keywords, shell arithmetic, the
-e option to echo, and many other things.
Debian
policy looks at SUSv3 Shell Command Language
and states:
If a shell script requires non-SUSv3 features from the shell interpreter
other than those listed above, the appropriate shell must be specified in
the first line of the script (e.g.,
#!/bin/bash) and the package
must depend on the package providing the shell (unless the shell package
is marked "Essential" [policy 3.6], as in the case of
bash).
You may wish to restrict your script to SUSv3 features plus the above set
when possible so that it may use /bin/sh as its interpreter. If
your script works with dash (originally called ash), it
probably complies with the above requirements, but if you are in doubt,
use /bin/bash.
This raises the issue of whether dash should be "essential"
[see Debian
policy section 3.8].
bash is "essential" meaning that it must be installed on every
Debian system. If dash does not become "essential" then every
script with /bin/sh as its interpreter must depend on
dash to insure that it is installed and usable by /bin/sh
(once the change is made).
That this change will be made is mostly not under debate, it is more a
matter of when it will be fully implemented. Those that oppose the move
simply want a choice, which exists using dpkg-reconfigure dash.
Meanwhile users should be looking at their own scripts to see if they will
break once /bin/sh defaults to dash.
(
Log in to post comments)