Which Shell?

Common Shells

When writing a Unix shell script, there are two families of scripting languages to choose from: Bourne shell and C shell. These were the first two mainstream shells for Unix, and all mainstream shells that have come since are compatible with one or the other.

Some of most popular new shells derived from Bourne shell are Bourne again shell (bash), Debian Almquist Shell (dash), KornShell (ksh), and Z shell (zsh). T shell (TENEX C shell, tcsh) is the only mainstream extension of C shell.

  • Bourne shell family
    • Bourne shell (sh)
    • Bourne again shell (bash)
    • Debian Almquist shell (dash)

    • Korn shell (ksh)
    • Z-shell (zsh)
  • C shell family
    • C shell (csh)
    • T shell (tcsh)

Both Bourne shell and C shell have their own pros and cons. C shell syntax is cleaner, more intuitive, and more similar to the C programming language (hence the name C shell). However, C shell lacks some features such as subprograms (although C shell scripts can run other C shell scripts, which is arguably a better approach in many situations).

Bourne shell is used almost universally for Unix system scripts, while C shell is fairly popular in some areas of scientific research. Every Unix system has a Bourne shell in /bin/sh. All other shells may need to be installed via a package manager on some systems. Hence, using POSIX Bourne shell syntax (not bash, ksh, or zsh) for scripts maximizes their portability by ensuring that they will run on any Unix system.

If your script contains only external commands, then it actually won't matter which shell runs it. However, most scripts utilize the shell's internal commands, control structures, and features like redirection and pipes, which differ among shells.

More modern shells such as bash, ksh, and tcsh, are backward-compatible with Bourne shell or C shell. This means that shells such as bash and dash can run POSIX Bourne shell scripts. In fact, on some systems, sh is just a link to bash or dash. The extended shells add some additional scripting constructs and convenient interactive features. Most of the advantages of shells such as bash and tcsh are in the interactive features, like auto-completion and command editing. The added constructs for scripting are nice, but do not make scripting significantly easier.

Practice

Note

Be sure to thoroughly review the instructions in Section 2, “Practice Problem Instructions” before doing the practice problems below.
  1. What are the two families of shell programs?

  2. State one advantage of Bourne shell for scripting and one advantage of C shell.

  3. What is the advantage of using POSIX Bourne shell for scripting rather than an extended shell such as bash or dash?

  4. What is the disadvantage of using POSIX Bourne shell for scripting rather than an extended shell such as bash or dash?