-->
Previous Table of Contents Next


Looking at Different Shells

Red Hat Linux provides the following shells: sh, bash (Bourne Again SHell), tcsh, csh, pdksh (Public Domain Korn SHell), zsh, ash, and mc. Try each shell and pick one you like. This chapter concentrates on the sh and bash shells, because most Linux distributions install bash as the default shell. Also, sh is available on most UNIX systems, and you’ll find many shell scripts written with sh commands.

Because the shell serves as the primary interface between the operating system and the user, many users identify the shell with Linux. They expect the shell to be programmable, but the shell isn’t part of the kernel of the operating system. With enough background in systems programming and knowledge of the Linux operating system, you can write a program that can become a shell.

Although many different shells have been created, there are several prevalent shells: the Bourne, C, T, and Korn shells. The Bourne shell is the oldest, and the others have some features not in the Bourne shell. In fact, Linux uses a variation of the Bourne shell, the bash shell, as its default shell. (To the novice user, the Bourne and Korn shells look identical; indeed, the Korn shell was developed from the Bourne shell.)


NOTE:  The Slackware 96 distribution doesn’t provide a copy of the Korn shell. The Red Hat distribution provides a version of the Korn shell called pdksh, which stands for Public Domain Korn Shell.

The C shell was developed at the University of California at Berkeley as a shell more suitable for programmers than the Bourne shell. The T shell is a derivative of the C shell. The Korn shell has all the features of the C shell but uses the syntax of the Bourne shell. If all of this sounds confusing at the moment, don’t worry. You can do a lot without knowing or worrying about the shell you’re using.

In their simplest forms, the Bourne and Korn shells use the dollar sign ($) as the standard prompt; the C shell uses the percent sign (%) as the prompt. Fortunately (or not, depending on your disposition), these prompts can be changed so that you may or may not see either the dollar or the percent sign when you first log in.

The Bourne shell, known as sh, is the original UNIX shell. It was written by Steve Bourne with some help and ideas from John Mashey, both of AT&T Bell Laboratories, and is available on all Linux systems. The executable program for this shell is in the file /bin/sh. Because the Bourne shell is available on all Linux systems and it has all the properties described in the preceding sections as well as powerful programming capabilities, it has become a widely used shell.


NOTE:  Many of the shell script examples in this chapter are written so that they can be used with the Bourne shell. Shell scripts are sequences of shell commands, normally written with an ASCII editor such as vi. You can think of shell scripts as similar to DOS batch files.


See “Introducing vi,” p. 178

The C shell, known as csh, was developed by Bill Joy at the University of California at Berkeley. The students and faculty at Berkeley have had a great deal of influence on UNIX and hence Linux. Two results of that influence are the C shell and the vi text editor. The Bourne shell has superior shell programming capabilities, but the C shell was developed to reflect the fact that computing was becoming more interactive. The executable program for the C shell is in the file /bin/csh.

The syntax of the C shell closely resembles the C programming language. This is one reason that shell scripts written for the C shell often can’t run under the Bourne or Korn shell (executables compiled under the C shell will often behave properly, though). But the C shell has some desirable features not available in the Bourne shell: command editing, history, and aliasing.

The default Linux shell is the bash shell. bash is located in /bin/bash and provides several enhanced features detailed in the next few paragraphs, such as command editing, command history, and command completion.

All Linux systems have the bash shell. You also might have installed several other shells during installation—for example, the C shell or the T shell. To determine which shell you’re using, enter


echo $SHELL

The echo command prints whatever follows the word echo to the terminal screen. SHELL is a variable, maintained by the shell, that holds the name of your current shell; $SHELL is the value of that variable.

To see whether the C shell is available, enter this command:


csh

If you see the percent sign (%) as the prompt, the C shell is available and running (enter exit to return to your previous shell). If you’re logged in as root, the prompt for the C shell is #. If you get an error message, the C shell isn’t available to you.

The shell you use as a login shell is specified in the password file. Each login ID is represented by a record or line in the password file; the last field in the record specifies your login shell. To change your login shell, you must change that field. The act of changing to another shell is relatively easy. Before you change shells, however, decide whether learning a new syntax and operating method are worth the change. See the man pages for detailed information on your shell’s syntax.


CAUTION:  
Never directly edit the password file (/etc/passwd) in Linux. Because of the security features added to these releases, the password file should be manipulated only with the appropriate commands. For example, with Slackware Linux, to change to the C shell by using usermod, enter usermod -s/bin/csh user, where user is the user ID of the user for whom you’re changing the shell. This caution is especially important if you are using the shadow suite of utilities.

Several other shells are available; some are proprietary and others are available on the Internet or through other sources. To determine which shell you want to use, simply read the man pages for the various shells and give each a try. Because shells are programs, you can run them just like any other application.


Previous Table of Contents Next