Cracking the UNIX Shell - dummies

By John R. Levine, Margaret Levine Young

After you figure out which general variety of UNIX you have, you must figure out one other vital consideration: which shell you’re using. Although you may say, “I don’t want to use any shell; I just want to get some work done,” the shell is the only way to get to where you want to be.

The guts of UNIX are buried deep in the bowels of the computer. The guts don’t deign to deal with such insignificant details as determining what users may want to do. That nasty business is delegated to a category of programs known as shells.A shell is a program that waits for you to type a command and then executes it. From the UNIX point of view, a shell is nothing special, other than the first program UNIX runs after you log in. Because you can designate any old program to run when you log in, any fool can write a shell — indeed, many have done so. About a dozen UNIX shells are floating around, all slightly incompatible with each other (you probably guessed that).

Fortunately, all the popular shells fall into two groups: the Bourne (or Korn or BASH) shell and the C shell. If you can figure out which of the two categories your shell is in, you can get some work done. (You’re getting close!)

You can easily tell which kind of shell you’re using. If UNIX displays a $ after you log in, you have a Bourne-style shell; if UNIX displays a %, you’re using the C shell. Traditionally, System V systems use the Bourne shell, and BSD systems use the C shell. These days, however, because all versions of UNIX come with both shells, you get whichever one your system administrator likes better. Preferences in command languages are similar to preferences in underwear: People like what they like, so you get what you get. These days most people like BASH, a souped-up Bourne-style shell.

Linux systems usually come with the BASH shell, a Bourne-style shell.

If you use a GUI, you see windows and icons, not a boring little UNIX prompt, after you log in. You still need to use a UNIX shell from time to time, however, usually to perform housekeeping tasks.

The Bourne and Bourne Again shells

The most widely used UNIX shell is the Bourne shell, named after Steve Bourne, who originally wrote it. The Bourne shell is on all UNIX systems. It prompts you with $, after which you type a command and press Enter. Like all UNIX programs, the Bourne shell itself is a program, and its program name is sh. Clever, eh?

A few alternative versions of the original Bourne shell exist, most notably the Bourne Again shell (or BASH, whose program name is bash) from the GNU crowd. This version of the Bourne shell is used in many places because of its price — it’s free. BASH is enough like the original Bourne shell that anything said about the Bourne shell applies also to BASH. The most notable advantage of BASH is that it has “command editing,” a fancy way of saying that you can press the arrow keys on your keyboard to correct your commands as you’re typing them, just as you can with DOS (oops, better not say that when any UNIX fans are listening).

The Korn-on-the-cob shell

After the Bourne shell was in common use for a couple of years, it became apparent to many people that the shell was so simple and coherent that one person could understand all its features and use them all effectively. Fortunately, this shameful situation was remedied by a guy named Dave Korn, who added about a thousand new features to the Bourne shell and ended up with the Korn shell (called ksh). Because most of the new features are of interest only to people who write shell scripts (sequences of shell commands saved in a file), you can consider the Korn shell the same as the Bourne shell. Most versions of the Korn shell also have command editing.

She sells C shells

No, the C shell wasn’t written by someone named C. It was written by Bill. (He sells C shells by the C shore? Probably.) The C shell’s program name is csh.

The most notable difference between the C shell and the other leading shell brands is that the C shell has many more magic characters (characters that do something special when you type them). Fortunately, unless you use a number of commands with names like ed!3x, these characters aren’t a problem.

Many versions of the C shell exist; most of them differ in which bugs are fixed and which are still there. You may run into a program called tcsh, a slightly extended C shell with command editing.