Shore Are a Lot of Shells!
Steven Zeil
Although you may not have thought of it as such, the Unix commands that you type into your keyboard constitute a programming language. This language is interpreted by a program called a shell.
The Unix operating system is positively overrun with different shell languages. You can find out what whell you are using by giving the command
echo $SHELL
Whatever shell you are using, it is only one of several possibilities. And, although we have not touched on it yet, that is a full programming language, including control flow instructions for branching and loops.
csh
and tcsh
constitute one family of commonly used shells. They languages they accept are nearly identical. tcsh
adds features that are of especial use when typing commands directly to the shell. csh
is preferred when writing scripts, short programs in the shell language, if only because csh
is more likely to be installed on any given Unix system.
Another family is the sh
family, which contains sh
, bsh
, and bash
. sh
is commonly used for writing scripts but lacks some of the conveniences we would want in an interactive shell. bsh
is the “Bourne shell” (named for its inventor), and bash
, the default interactive shell for Linux and CygWin, is the “Bourne Again shell”.
These are by no means the only shell or scripting languages available for Unix, but they’ll do for now.
What distinguishes these shell languages from more general-purpose programming languages is their emphasis on simplicity. Scripting languages are designed to permit immediate translation. If, every time you typed a command, you had to wait while a full-fledged compiler was loaded and executed to process the characters you had typed, the time delays would have you screaming in frustration. Instead, these languages are designed to very quickly determine (usually by examining the first word you typed) if the command is a special command “built in” to the shell. Anything else is a program to be launched.
If you are using a shell in the ssh/bsh/bash family, the command type
can be used to determine if a given word represents a built-in shell command, a program (and if so, where that program is located), or something else. Try logging in and giving the following commands:
type g++
type cp
type echo
type more
type if
type type
type foobar
If your login shell is not in the sh/bash family, you can try out these commands by typing “bash” or “sh” first, then trying those commands, then type “exit” to return to your normal shell.
We’ll concentrate on the csh
for scripting purposes, with some notes on how sh
-like languages, including bash
, differ from csh
.