/bin/bash vs. /bin/sh

David C. Niemi (niemidc@clark.net)
Mon, 18 Sep 1995 00:13:48 -0400 (EDT)

On Sun, 17 Sep 1995, Andrew Tristan wrote:
> While we're complaining about modutils: it took me a long time to figure
> out that 'depmod -a' depends on having a /bin/sh that knows how to deal
> with csh-type string expansion (with {}). After hours of screwing with
> it I finally strace'd depmod and got things like:
> access("/linux/modules/*.{mod,o}", 4) = -1 (No such file or directory)
> Ohhhh...
> Call me a traditionalist if you must, but the idea of having /bin/sh
> with all this junk built into it is Not the Right Thing to Do. I always
> build two copies of bash, one kitchen-sink version and one minimal
> version. The only time I use the bloated, kitchen-sink version is to
> set up module dependencies.
> There, I feel better.

This points out a bad habit of *lots* of Linux developers: they (usually
inadvertently) assume that /bin/sh is really a full version of Bash or
that features they are accustomed to from Bash are in every Bourne Shell.
There are some good reasons not to use a full version of bash as /bin/sh,
the two most important of which are (1) it is not 100% Bourne-shell
compatible as normally configured; (2) the added overhead of running a
much bigger executable for every Bourne shell script; and (3) it results
in you tending not to realize that your shell scripts are non-portable
outside of Linux (or even to many Linux machines).

A couple of developers I have pointed this out to have been quite gracious
about fixing it, but many more are blissfully unaware. The most common
example is using the "source" command instead of ".", which bash also
understands. If Bash features are truly needed or you don't feel like
finding out if your script is portable, please change the header to say
"#!/bin/bash" instead of "#!/bin/sh"; at least then it should work on all
machines that have bash.

I personally found that the smallest, most compatible Bourne shell I could
make was by taking out all the non-Bourne-shell options from pdksh; I got
it down to 108 KB (ELF) and it could probably be made smaller. At any
rate this is much smaller than a minimal version of Bash, though both work
quite well. Ash, OTOH, is nowhere near compatible with Bourne Shell
(though it is nice and small). One other bad Bourne Shell clone is SCO's
/bin/sh, which is very different from sh on any modern UNIX (I would call
it broken, but maybe it's just antique).

----David C. Niemi---niemidc@clark.net---703-904-3596---Reston, VA USA----
We have a long and rich history, but no future save what we dare to dream.