Shell Preference

I’d like to address the issue of shells.

Not this kind of shell:

Not what I mean

Not what I mean

Or this kind:

Not this kind, either

Not this kind, either

No, I’m talking about the geeky kind of shell:

A coloful Linux BASH prompt

A coloful Linux BASH prompt

WTF is a shell?

A shell is, quite simply, a program that allows a user to give commands to a UNIX (-like) system.  If you don’t have a graphical greeter set up, it’s what you see when you log in.  It also happens to be what processes all of the system startup scripts that tell the computer important particulars about networks, time and date information, language settings, and other fun things.  A shell is an example of a more generic kind of program:  the command interpreter.  Technically, MS-DOS command.com, Windows NT’s cmd.exe, UNIX shells, C64 BASIC, and Perl are all examples of command interpreters.

Okay, so why do I care about shells?

If you’re a GUI kind of person, then you probably don’t give a crap how your shell behaves since you rarely use it.  But it’s still good to know.  And I’m a command line freak.  This is for all of the command line freaks and I think is something that all UNIX users should know.

The UNIX Shell Family Tree

In the Beginning, Ken Thompson created a shell for UNIX.  It was just called The Shell since it was the only one.  Nowadays it’s retronymmed to the Thompson Shell.  It sucked.  He wanted to do more with it but he had more important things to do.  Eventually, the BSD boys (not Beastie Boys) got tired of the inadequacies and feeble attempts at fixing Thompson’s completely retarded shell.  At the same time, the team of developers in charge of the True UNIX at the time set to work developing a drop-in replacement for the weak Thompson Shell.  Bill Joy of BSD and Steven Bourne of Bell Labs both came up with new shells for UNIX to replace Ken Thompson’s original shell.  The C shell was released with 2BSD and the Bourne Shell was released with UNIX System 7.  Thus begin the lineage of the Two Great Shells.

The Bourne Shell

The most ubiquitous UNIX shell today is the Bourne Shell, a descendant of Steven Bourne’s original replacement for the Thompson Shell.  Modern systems almost never actually have the actual Bourne shell anymore since it was rather limited, but instead have one or several shells that are fully backward-compatible with the original Bourne shell.  In fact, both POSIX and the Single UNIX Standard require that /bin/sh be either a true Bourne shell or a link to a 100% compatible replacement for the Bourne shell.

Default Prompt:  $
Scripting Format:  Bourne
Customizable Prompt:  Yes
Color Support:  No
Job Support:  No
Screen Support:  No
Current Distributions:  Free/Net/OpenBSD, Solaris, HP-UX, AIX, Tru64 UNIX, SCO OpenServer

Korn Shell

It was written by David Korn as a middle-road compromise between the C shell of BSD and the Bourne shell of AT&T Unix.  The original Korn shell is still copyrighted so it can only be distributed with systems that support this copyright.  As a result, an open source clone called pdksh is available and distributed with OpenBSD. ksh93 is a from-scratch rewrite of KSH with updates for modern systems.  It is free and open source.

Default Prompt:  $
Scripting Format:  Bourne
Customizable Prompt:  Yes
Color Support:  No
Job Support:  Yes
Screen Support:  Yes
Current Distributions:  Solaris, HP-UX, AIX, Tru64 UNIX, SCO OpenServer; OpenBSD (pdksh);  Linux, OpenSolaris, FreeBSD, NetBSD (ksh93)

Bash

Bash, or the Bourne Again Shell, is the most widely-used shell in modern UNIX systems.  It was written by the GNU project as a replacement for the Bourne shell but with all of the features of the Korn and C shells.  It is distributed with all Linux systems except those based on Debian.

Default Prompt:  [user@hostname dir] $
Scripting Format:  Bourne
Customizable Prompt:  Yes
Color Support:  Yes
Job Support:  Yes
Screen Support:  Yes
Current Distributions:  Free/Net/OpenBSD, Linux (except Debian-based distros), OpenSolaris, MacOS X

Dash

The Debian Almquist shell is a port of the Almquist shell (ash) from NetBSD to Debian GNU/Linux.  It’s faster, more secure, and more reliable than Bash while supporting all of the same functionality.  However, it is not 100% compatible with Bash.

Default Prompt:  [user@hostname dir] $
Scripting Format:  Bourne
Customizable Prompt:  Yes
Color Support:  Yes
Job Support:  Yes
Screen Support:  Yes
Current Distributions:  Debian GNU/Linux, OpenBSD

C Shell

The C shell was written by Bill Joy (same dude who wrote vi) for BSD.  The intent was that since C was the popular language at the time, coders would be more at home giving commands and writing scripts with a C-like syntax.  He was half right.  Everyday users loved the simplicity of the interactive command like and features like Job Control were just plain awesome.  Scripting was another story.  C coders hated it because it was just enough C to confuse them but not enough to actually do anything useful.  Bourne Shell scripters were just plain baffled by the C shell’s completely daft scripting conventions.  C shell remains a very popular shell on commercial UNIX systems.

Default Prompt:  Hostname%
Scripting Format:  C-like
Customizable Prompt:  Yes
Color Support:  No
Job Support:  Yes
Screen Support:  No
Current Distributions:  Solaris, HP-UX, AIX, Tru64 UNIX, SCO OpenServer

TENEX C Shell

tcsh or TENEX C Shell is based on a port of the C shell to the TENEX operating system.  It was then ported back onto BSD with all the features it gained while on TENEX.  Nowadays, it’s a free replacement for the C shell with some cool features from other shells like Bash.

Default Prompt:  >
Scripting Format:  C-like
Customizable Prompt:  Yes
Color Support:  Yes
Job Support:  Yes
Screen Support:  Yes
Current Distributions:  Free/Net/OpenBSD, Linux, OpenSolaris

The Z Shell

ZSH is in a class by itself because it was descended from both TCSH and Bash as well as having some fun stuff from the Korn shell mixed in.  The name comes from a bit of confusion resulting from a professor’s login name being zsh and others thinking that since it ended in sh it must be a new shell.  The Z shell is extremely versatile and flexible, offering the most complete command interpreting environment in UNIX today.  Its loadable module support enables even complex functionality like UNIX Domain Sockets, FTP, Telnet, and SSH to be built into its command structure.

Default Prompt:  Hostname%
Scripting Format:  Bourne
Customizable Prompt:  Yes
Color Support:  Yes
Job Support:  Yes
Screen Support:  Yes
Current Distributions:  Free/Net/OpenBSD, Linux, OpenSolaris

Your Mission:

Tell me which shell you use and why!  On my Solaris workstation, I use CSH for my login shell but drop to KSH to do system admin stuff.  On the router I use the default BASH that’s built into busybox.  On the audio station, I use Bash since it’s the default and works fine for what I do.  On the server I also use Bash for the same reasons.  I do love ZSH but I rarely take advantage of all its features so I don’t usually install it.  Now tell me your favorite shells!

, , , , , ,

  1. #1 by Joshua on July 20, 2009 - 10:25 AM

    This is how I know I’m a UNIX geek. I just typed the command nice find / -type f -exec grep -H '#!/bin/bash' \{\} \; > ~/bashscripts 2>/dev/null fully aware that it would search my filesystems, read the contents of each file into memory, search it for the string #!/bin/bash and print its name into a file called “bashscripts” in my home directory. And I did this without having to think about what I was typing!

    • #2 by Joshua on July 20, 2009 - 11:37 AM

      I was doing this to find out if Red Hat’s system init scripts made use of explicit bashisms that would make calling /bin/sh the Wrong Thing. They do. The only scripts that call /bin/sh on the system are the Apache Tomcat scripts. Everything else shebangs /bin/bash.

  2. #3 by Chadwick on July 20, 2009 - 10:40 AM

    My Kubuntu would seem to come with Dash, which I use because I find it to be satisfactorily functional.

    • #4 by Joshua on July 20, 2009 - 11:35 AM

      Which would make total sense, Kubuntu being the KDE flavor of Ubuntu which is based on Debian whose Bourne-compatible shell is Dash. I find it interesting that although Bash is the official GNU shell, Debian, who insists on being called Debian GNU/Linux, doesn’t use the official GNU shell but instead makes their own :)

      • #5 by Joshua on July 20, 2009 - 11:36 AM

        That said, not much separates Bash and Dash except a few nonstandard undocumented scripting constructions that appear in Bash but nowhere else.

        • #6 by Chadwick on July 20, 2009 - 11:38 AM

          Yeah, well it seems that up until 6.10, the Ubuntu distros were using Bash. Or so my research tells me.

          • #7 by Joshua on July 20, 2009 - 11:42 AM

            Da. They used Bash because it was more commonplace and probably simpler just to copy/paste initscripts. When they switched to Dash they found that their initscripts made use of bash-exclusive undocumented features that needed to be standardized.

  3. #8 by Andrew D. on July 20, 2009 - 1:28 PM

    Bash, for three reasons.

    1. It’s included in most distros by default.
    2. The distros that don’t include it at least remain compatible with it.
    3. I know how to program in it.

    • #9 by Joshua on July 22, 2009 - 7:02 PM

      Unless you use all the awesome Bash-centric stuff like the [[ ]] test operators, for (( )), if (( )) and ((3**3)) syntax, you can technically use any Bourne-compatible shell to interpret the script. It’s a fun experiment to get all the FOSS Bourne-compatible shells and run different scripts against them to see which ones work and which don’t and note which statements cause them to choke. I just typed “chode” for the first time in my life. I meant to type “choke.” I fixed it now :P

  4. #10 by Joshua on July 20, 2009 - 3:27 PM

    UPDATE: Turns out I use CSH on the audio station. I booted it just now. CSH makes sense, being the default workstation shell.

  5. #11 by Joshua on July 21, 2010 - 10:59 AM

    I use:

    • KSH for system admin tasks.
    • CSH for normal non-admin work.
    • Bash for root logins on Linux machines.

    I have KSH and CSH both set up to use VI mode so I can do cool things on the command line quickly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 48 other followers

%d bloggers like this: