Shell Is sh Bourne Shell or POSIX shell. What is the difference

as we understand it, FreeBSD's POSIX-compliant shell is Bourne-compatible but was written by Almquist. "Bourne shell" is a formation by contrast with "C shell". POSIX requires that /bin/sh be Bourne-compatible, but it's OK to be a superset.
 
Apparently the documentation is up for a change on this and a lot of Bourne shell mentions are changed to POSIX https://reviews.freebsd.org/D56054:
The FreeBSD shell is a POSIX compatible shell. It evolved over several
decades from the Almquist shell, which was preceeded a decade before
that by the Bourne shell. Most readers today have never seen a Bourne
shell. If someone wants to learn to use our shell, they need to look for
tutorials on the POSIX shell. Align descriptions through out the tree
with this reality, consistent with it's manual and common parlance.
 
For those near NYC, the local BSD user group will have a fireside chat with Bourne the man himself on May 13.
Is this being recorded or streamed?

Stephen Bourne's talk at BSDCan 2015 was absolutely excellent (YouTube link), and one of the major sources for that Reddit post. For anyone who thought the Almquist shell was just a freely licensed clone of the Bourne shell (sadly quite a common claim), it's instructive to listen to Bourne talk about how hard he found it to deal with quoting* and how much of an improvement Kenneth Almquist made.

Another interesting thing about that talk: Bourne claims to have persuaded Dennis Ritchie to introduce void into C, since it was a concept he missed from his ALGOL days at the Cambridge University Mathematical Laboratory (nowadays the Computer Laboratory). You might want to ask him more about that anecdote if you get a chance. I don't think many C programmers realise the early versions of C didn't have void.

Bourne's ALGOL tastes have left a lasting impression with his syntax choices (if...fi and we would have got do...od instead of do...done if 'od' wasn't already taken by 'octal dump') and he even programmed his shell in "Bournegol", using some extraordinary macros to make C look like ALGOL. Allegedly one of the inspirations for The International Obfuscated C Code Contest - he's not proud of it!

* Re quoting: it's interesting this is something Bourne found so hard because it's deeply tied to the genesis of shells as an idea. Louis Pouzin invented both the concept and the name "shell" crediting Christopher Strachey's macro generator for his inspiration, in particular the way it could quote and pass arguments. Pouzin's big idea was to apply these principles for a command language that could process scripts. He viewed his first "shell" as RUNCOM, a macro command (i.e. script) processor released in 1963 for the Compatible Time-Sharing System (CTSS) but it's his 1965 design document for a shell for Multics that is more recognisable. Ken Thompson's first Unix shell, and the PWB shell (Mashey shell) that was it's first major improvement pre-Bourne, are very obviously based on the Multics shell. I dug out some lovely documents and videos including of the Multics shell whirling away including on a typewriter - I like the way it hides your password by repeatedly overprinting garbage letters on a line before returning the carriage to type, so what the typist enters is immediately hidden among the mess.
 
Original bourne shell did not have command line editing or command line history that we have in the present FreeBSD SH.
The original Almquist shell didn't have command line editing or history either. In fact it's also something that Korn initially opposed implementing on his shell too. I write about this quite a lot in that Reddit piece about FreeBSD's sh(1) not really being a Bourne shell. Everyone at AT&T, as well as Almquist (who was independent), seems to have seen this as a job for your terminal driver to implement someday, and not a task that rightly belongs to your shell.

Bourne describes his objections in that BSDCan talk. David Korn wrote a historical note about his shell here, including how ksh(1) ended up with both vi and emacs line editing modes due to editor wars within AT&T, once it became clear the terminal driver wasn't going to improve any time soon. Almquist's release notes for his shell include 20 things he did different to Bourne (there were other undocumented ones) but also some "improvements" he omitted deliberately, with history in the shell being one of them (he suggested BSD users start using his atty terminal software instead).

Bill Joy at Berkeley found the Bourne shell's lack of interactivity very disappointing - he'd abandoned a previous attempt at making a new shell to replace the Thompson shell because he'd heard this new replacement would be coming out of Bell Labs soon, but this - plus the fact he thought shell scripts should look more like C than ALGOL since that's what Unix hackers mainly wrote in - drove him to write the original BSD csh(1). There was an even bigger improvement with auto-completion in tcsh(1) of course, via a mix of Ken Greer (partly while at CMU, hence "T" for TENEX which inspired him, and later at HP Labs) and Mike Ellis at Fairchild A.I. Labs who added recognition and completion of command names (as opposed to file names). Curiously some of Green's tcsh(1) code actually predates the Bourne shell, but of course tcsh(1) wasn't released until a few years later. A lot of these shells, or components of them, were being used internally or even just personally for years before they got an official release, which is one of the reasons it's hard to establish priority for stuff!
 
Last edited:
Is this post historically accurate. I always thought sh shell is Bourne shell for the command line at the terminal. Or is it correct to call it Almquist shell.

Maybe the original poster is here in the forums.
Here I am!! I welcome any corrections and have tried to be as accurate as possible. I based it on a lot of sources, including reading what Mashey (PWB), Bourne, Joy (csh), Almquist, Korn (ksh) and Greer (tcsh) have written or said about their respective shells. Given that many sources contradict, I've preferred original sources where possible - quite a few Usenet posts in there! It's common for books written after the fact to date things by their release dates but this sometimes get the sequencing wrong. There's also a long-running controversy (even back to 1980s flame wars) over which of csh and the Bourne shell is actually older, and Bill Joy himself admitted he couldn't remember all the details of his shell development. Particularly because csh wasn't the only one he worked on - despite it being the one that's left the biggest legacy, dig around enough and you'll start seeing references to "nsh" too. (If anyone knows more about that one, let me know!)

Yep, FreeBSD's /bin/sh is ash, or Almquist's shell. It's a Bourne and POSIX compatible shell.

It's been quite heavily modified over the years though.

There's a fantastic Almquist shell "family tree", documenting how it's changed over the years (including the addition of features like history which Almquist deliberately omitted) and across the various OSes it's ended up in, produced by Sven Mascheck: www.in-ulm.de/~mascheck/various/ash/

It spent some time "incubating" in Berkeley Unix and then 386BSD, before the NetBSD/FreeBSD split produced a bit of divergence. After that came a proliferation of "ash" or "dash" shells in Linux which stem from the NetBSD sh(1).
 
Back
Top