Re: [Hampshire] Bash -> Dash for sh. Is it safe?

Top Page

Reply to this message
Author: Graham Bleach
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Bash -> Dash for sh. Is it safe?
On 01/06/07, Dr Adam J Trickett <adam.trickett@???> wrote:
> I've seen a few reference to using dash rather than bash as the
> symlink for sh rather than bash. Dash is mostly POSIX compliant,
> and very much smaller than bash so scripts without bashism
> run quite a bit faster.


Did you see any benchmarks to prove that dash is actually faster? Most
shell scripts I write and maintain actually spend most of their time
running executables, which means I'd be surprised if there was any
appreciable improvement in performance.

> I've also seen people complain recently that a some scripts
> on an ubuntu box break because though they called for /bin/sh
> they were relying on a Bashism. I'm not sure which ubuntu
> versions have taken the switch, or if it's the default
> now.


/bin/sh is certainly a symlink to /bin/bash in Feisty (7.04). I
believe the transition happened in Edgy.

> I'm not proposing to changing my login shell to dash, but
> have anyone tried changing sh to dash and what kind of
> problems did you see? I also think running my scripts
> under other Bourne/POSIX shells is good practice for me
> as well.


I haven't specifically made that transition, but I have had experience
of maintaining init scripts for both Solaris and Linux, where the
Linux system used bash and the Solaris systems used a real bourne
shell [*]

The portability problems I encountered were pretty much all down to
use of bash extras such as:

- Arrays.
- $( ... ) for command substitution
- Extra options for shell builtins such as test and echo.

Other than the specific example of portable init scripts and other
applications where you can't assume bash is installed, I never use
bourne/dash - bash and ksh have some useful extra features that I see
no reason to deprive myself of.

G

[*] In Solaris there was the added complication that you could put any
shebang line you wanted in an init script, but when invoked by init it
would be executed by /sbin/sh, even if the first line read
#!/bin/bash. Things would work when executed manually, but fail at the
next reboot, often months later.