Dash Shell – Purpose of sh Being Linked to Dash

bashdash-shell

I am wondering what the point of sh being symbolic linked to dash is? I understand that dash is supposed to be faster than bash, but I am uncertain why the original sh shell isn't present in sh.

Or if anything why isn't sh linked to bash?

Best Answer

The short answer to “why the original sh shell isn't present in sh” is that there's no original sh.

Well, ok, there is: it's the Thompson shell. Version 1 had some of the features we know today, in particular redirection and pipes (read Dennis Ritchie's paper on early Unix history). Later versions added features such as background execution with &, globbing (implemented with an external program), and some forms of quoting, but it didn't have variables or nested control structures. Conditionals and loops were provided via external programs if (which took one condition and one command as arguments) and goto (which worked by changing the file position of its parent in the script file).

In 1979, in Unix V7, the Thompson shell was replaced as /bin/sh by the Bourne shell. The first release already had many of the features that are present in dash today, and subsequent versions introduced many more. A few years later, the Korn shell came onto the scene, with a growing feature set; many Unix variants installed it under the name ksh.

In 1992, POSIX codified a minimum set of sh features that was basically Bourne plus a few things. Any system that called itself “Unix” had to implement at least these features. Commercial Unix systems usually used ksh as the POSIX sh, but a few (e.g. OSF/1) had their own.

Neither the Bourne shell nor the Korn shell were open source until fairly recently, so when the Linux world started to form in the mid-1990s, they weren't available. /bin/sh had to be something else. Most Linux distributions went for bash, a shell from the GNU project that tended to be between Bourne and Korn in terms of scripting features, and much better than either for interactive use). The only viable alternative was pdksh (“public domain Korn shell”), a free (now discontinued, but living on as mksh, which is actively developed), but I don't remember a Linux distribution using pdksh as /bin/sh, I don't know why, I guess because Linux distributions were always GNU/Linux distributions, basically shipping GNU versions of any tool for which a GNU version did exist.

There were also several open source implementations of sh called “ash”, most notably the Almquist shell, but they were very incomplete, lacking some POSIX features that people wanted to use. A programmer who was a Debian maintainer, Herbert Xu, extended ash to make it POSIX compliant. Eventually his version was renamed to dash, and there was some push to make it /bin/sh in Debian instead of bash. Ubuntu started out before Debian started to systematically treat bashisms (the use of bash-specific functionality in #!/bin/sh scripts) as bugs. Both switched a later (Ubuntu 6.10, Debian only in 2009 (it was a goal for lenny but the switch was only made after the lenny release, i.e. in squeeze)).

A major reason for using dash as rather than bash as /bin/sh is that it's significantly faster. This was especially important for Ubuntu, which has striven to keep boot times short since the beginning. Dash also tends to use less memory than bash, which is somewhat important for wrapper scripts that stay around just to do a bit of cleanup when the underlying program exits. Another benefit of dash is that it only relies on libc (the core system library) whereas bash also relies on terminal support libraries (it can't start without them, even to run a script); this means that dash has a better chance to keep working on a broken system.

At some point during the 21st century, the Korn shell went open source, and open source versions of the Bourne shell appeared (old versions, because development had ceased years before). But dash and bash were too firmly entrenched in the Linux world for them to gain any acceptance, especially the Bourne shell since its value today is only historical. Dash displaced bash because it had clear benefits, but none of the other contenders have any decisive advantage as /bin/sh.