Christopher B. Browne's Home Page

4. Unix Shells - csh, ksh, bash, zsh, ...

One of the powerful things about Unix is the extensive use of programmable shells, that is, programs (that are not part of the operating system kernel) that allow you to run programs and see their output. This wasn't a new innovation with Unix; the notion of having a replaceable "command shell" rather than a "monitor" tightly integrated with the OS kernel tends to be attributed to Multics.

In any case, the notion of having a powerful, programmable "shell" to allow you to control your environment has led to a proliferation of increasingly powerful shells.

  1. Bourne Shell

    The traditional Unix shell from the very early days. Unix folk need to have some knowledge of sh, as its syntax is what is used in system initialization routines, whether of the BSD or SYSV styles.

    Virtually any of the newer shells add, to it, such functionality as:

    • Command/filename completion (e.g. - spell part of the command name, hit a "hot key," and the shell will try to complete the name of the command/file;

    • History manipulation; some ability to re-run previous commands;

    • Command line editor (so you can edit and re-invoke previously run commands);

    • Definition schemes for aliases/functions to allow you to create custom behaviours.

  2. Bourne-Again Shell - Bash

    The FSF folks created an exceedingly souped-up version of the Bourne shell with automated command completion and plenty of additional functionality.

    Linux systems typically have chosen Bash as the "basic" shell used by default and for managing init . In 2010, that is starting to be significantly false, as Linux distributions are assortedly considering more limited but faster shell languages, as well as init implementations that implement specialized script evaluators, to improve bootup performance.

  3. Linux Shell Scripting with Bash

    This is a pretty comprehensive book that guides the reader on how to use Bash for a wide variety of purposes.

    It is very well-motivated; each chapter introduces the area it examines with an interesting anecdote, and presents a reasonably rich set of examples of how to use Bash along with other Unix tools to solve the problem at hand.

    It is not solely about Bash; it shows the use of process control tools like ps, kill, and such, text manipulation tools like grep , sort, cut, sed, and such, and version control using CVS . This is all well and proper: One of the major uses of shell scripting is to paste together other programs, and these examples support that.

    It is not focused on how to do unusual and abstruse things with Bash; if you're looking for "edge cases," you are probably better off looking through the INFO pages or even the source code. If your needs aren't that abstruse, then even relatively advanced script programmers should be able to learn a few things from the book...

  4. Learning the Bash Shell (Nutshell Handbooks)

  5. Working more productively with bash 2.x

  6. BASHISH - the good stuff.

  7. Advanced Bash-Scripting HOWTO - A guide to shell scripting, using Bash

  8. BashPitfalls - Greg's Wiki

  9. tcsh

    Extended version of the C Shell that adds such functionality as command completion, a command line editor, enhanced history manipulation. The "t" is for Tenex; this shell was initially deployed on the Tenex operating system.

  10. CSH Programming Considered Harmful

    CSH is a fairly nice interactive shell that has syntax that looks a lot more like C than that of the Bourne Shell. Traditionally, it was considerably superior for interactive use than sh, and back in my university days, preferred the "Tenex-extended" version called tcsh. Unfortunately, it has some very serious blemishes that make its use for writing substantial shell scripts inadvisable.

    Ksh is now nearly universally available, is much cleaner for programming shell scripts, and is thus generally preferable.

  11. Korn shell (ksh)

    This shell, written by David Korn, of Bell Labs, is now the defacto-standard shell for Unix systems, available on virtually any Unix-like system sold in the 1990's and beyond.

    It's a reasonable platform for both interactive system control as well as shell script programming, providing far superior functionality to the Bourne Shell. In many cases, it is quite a bit faster, too.

  12. MirOS: mksh - the MirBSD Korn Shell

    Successor to pdksh

  13. Chris Johnson's presentation on shell scripting for GTALUG

  14. ZSH Home

    zsh is a really powerful shell that provides fairly much the functionality of ksh, csh, and bash thrown together.

    One area in which it is dramatically powerful is in its ability to interactively evaluate and modify arguments. It can do command name completion, filename completion, and is extensible such that it can use programs to evaluate possible command completions.

    For instance, I use the MH mail system. zsh can do folder name completion for MH commands, so that I might type:

    % refile +Linux/Ad

    and press TAB zsh would execute MH code to look up the list of folders under Linux, and, since the only one matching what had been typed was Linux/Advocacy , zsh would complete the parameter thus:

    % refile +Linux/Advocacy/

    As a result, I seldom need to fully spell out anything; I need only spell enough, and then press TAB and let zsh spell it out for me.

  15. rc - Plan 9 shell

    Similar to the Bourne shell, but with a much more powerful set of programming features, and with an actual formal language definition, rc was created for the Plan 9 operating system.

  16. Es: A shell with higher-order functions

  17. Shell Quoting Guidelines, V 1.2

  18. FAQ for

  19. Other scripting languages

    Such as Perl, Tcl, Python, Ruby, REXX...

    These languages often allow linking in system libraries and offer more sophisticated data structures (e.g. - structured records, arrays, "objects", and such) which make them reasonable language candidates for implementing entire applications.

    "Scripting" languages were traditionally used to control the execution of the "real" programs written in "real programming languages;" it is no longer obvious that the distinction between "scripting" and "real" languages continues to be of terribly much importance.

  20. Shell Script Compiler

    Turns Unix Shell scripts into a compiled form (probably using C) such that the internal contents are not revealed. Running strings won't tell you what it does...

  21. EShell - The Emacs Shell

    A command shell implemented entirely in Elisp that runs in an Emacs buffer.

    Two primary reasons to get excited about this are if:

    • You run Emacs everywhere, making EShell more portable than its alternatives;

    • You have a great deal of ELisp functions that you would like to be able to use in scripts.

  22. Heiner's SHELLdorado

  23. ShellDorado Scripts by Category

  24. unix-shell at

  25. pshell

    A trivial Unix shell. No globbing; no internal commands; it just takes in lines that consist of single commands with arguments separated by blanks or tabs. Source code consists of one file with about 6K of C code.

  26. SCSH - a shell programming language using Scheme syntax

  27. Cash - a shell programming language using OCAML syntax

  28. Bush - a shell programming language using Ada syntax

  29. Zoidberg

    A modular Perl shell written, configured, and operated entirely in Perl. It aspires to be a fully operational login shell with all the features one normally expects. But it also gives direct access to Perl objects and data structures from the command line, and allows you to run Perl code within the scope of your command line. And it's named after one of the greatest characters on Futurama, so it must be good!

  30. autojump

    Sorta like cd, except that it learns which directories you like to visit, and offers you shortcuts.

  31. Common shell script mistakes

Contact me at