[sf-lug] BASH vs DASH to SH vs DASH ?

Rick Moen rick at linuxmafia.com
Tue Aug 9 00:56:02 PDT 2016


Quoting Jim Stockford (jim at well.com):

> Once upon a time there was a binary program named  sh  that was the
> Bourne shell.

Yes.   Stephen Bourne at Bell Labs wrote the original implementation,
which became the default user shell starting with Unix v. 7 in 1977.

> In modern times the  sh  has morphed from the name of a binary to a
> link that points to some binary program.

Not exactly.  More below.

> Because of history, the name  sh  is associated with the posix
> specification.

Well, it's associated with Bourne shells, and the POSIX shell
specification is derived from Bourne.

The POSIX specification basically borrowed the Bourne shell's idea of
what a user shell should provide and declared it a standard.  'Your
standard user shell in a POSIX-compliant system should do this list of
things in these ways', where what followed was a description of what the
Bourne shell did.

Because until recently the literal Bourne shell (Stephen Bourne's work
for AT&T Bell Labs) was proprietary, free / open source
re-implementations have sprung up.

For a long time, 'pdksh' was arguably the best offering, an open source 
reimplementation of David Korn's ksh (Korn shell), a sort of variant /
superset of the Bourne shell.  (And, more recently, the Korn shell
itself has become available open source.)  Also, Paul Falstad's zsh
(which he named in honour of Prof. Zhong Shao) was again a superset of
Bourne's features, and was open source.

The most familiar variant, bash (the Bourne Again Shell) was written by
Brian Fox for the GNU Project in 1989.  It's a clone of Bourne but with
a number of extensions / enhancements.

The POSIX committee abstracted their definition of the POSIX shell in
1992, the same year the Linux kernel first appeared -- basing it closely
on Bourne.  Almquist's 'ash' shell for NetBSD, of which dash is a small
variation, first appeared in 1989.

/bin/sh being a symlink is just one way of doing things.  E.g., on
RHEL/CentOS (last I checked), it's a hard link to a copy of bash.

Making /bin/sh be a symlink makes it convenient to manage it as an
indirect reference that can be easily repointed from one shell to
another.  Think of it as a form of system documentation:  You can just
look and say 'Ah, I see /bin/sh on this system points to $FOO.'


It's unclear whether the historic Bourne shell will ever be available
under an open source licence, but basically the world has moved on, and
if it suddenly appeared under (say) a permissive 2-clause BSD licence,
hardly anyone would care any more.  For interactive use, bash or ksh 
is a lot better.  For scripting, ash/dash is perfectly fine (or bash or
zsh, if you don't mind the bloat).


> So a  /bin/  directory might list ash and/or bash and/or dash and/or
> ksh and/or sh and/or zsh (and hopefully not csh or tcsh).

Why not all of them?

:r /etc/shells

# /etc/shells: valid login shells
/bin/ash
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/zsh
/bin/sash
/bin/zsh
/usr/bin/esh
/bin/dash
/usr/bin/screen
/bin/bash
/bin/rbash

> A long listing will likely show that most shell names are names of
> regular files and that  sh  is a link to one of the other files.

By 'link' you mean 'symlink', I would guess.  All files are links.
All _regular_ files are hard links to inodes.

> There's a good chance that the file for which  sh  is a link is a
> posix-compliant shell.

Well, it's definitely _supposed_ to be a POSIX-compliant shell.

On RHEL/CentOS (to the best of my recollection), it's a hard link to
bash -- and bash is only loosely POSIX compliant.

bash supports a --posix command-line option that forces it to be
_closer_ than it normally is to POSIX-compliance, but even that is not
entirely POSIX-compliant.  Not that most people care.


> So to compare BASH with DASH makes sense to me and to compare SH with
> DASH does not.

Not sure I follow.  Oh wait, ah!  You're assuming 'SH' is always a
symlink?  Well, no, it can be but doesn't need to be -- and 'sh'
historically meant Bourne.  (Not Ludlum's Bourne, note.)



> BASH is a bloated shell of the Bourne family and DASH is a lean and
> elegant shell of the Bourne family. 

One person's bloat is another person's necessary feature set, of course.


> SH is a name used to link to a posix-compliant shell of the Bourne
> family.

Not necessarily.





More information about the sf-lug mailing list