-->
Previous | Table of Contents | Next |
Several different kinds of shells are available on Linux and UNIX systems. The most common are the Bourne shell (called sh), the C shell (csh), and the Korn shell (ksh). Each of these three shells has its own advantages and disadvantages.
The Bourne shell was written by Steven Bourne. It is the original UNIX shell and is available on every UNIX system in existence. The Bourne shell is considered to be very good for UNIX shell programming, but it does not handle user interaction as well as some of the other shells available.
The C shell, written by Bill Joy, is much more responsive to user interaction. It supports features, such as command-line completion, that are not in the Bourne shell. The C shells programming interface is thought by many not to be as good as that of the Bourne shell but is used by many C programmers because the syntax of its programming language is similar to that of the C language. This is also why it is named the C shell.
The Korn shell (ksh) was written by Dave Korn. He took the best features of both the C shell and the Bourne shell and combined them into one that is completely compatible with the Bourne shell. ksh is efficient and has both a good interactive interface and a good programming interface.
Note:
There are many quality reference books about the Bourne, C, and Korn shells. If you want to use these shells instead of the three shells discussed in this and the next two chapters, you might want to find a good reference book on the particular shell you prefer. Because the shells included with Linux are the ones used by most people, we will concentrate on those.
In addition to these shells, many other shell programs took the basic features from one or more of the existing shells and combined them into a new version. The three newer shells that are discussed in this book are tcsh (an extension of csh), the Bourne Again Shell (bash, an extension of sh), and the Public Domain Korn Shell (pdksh, an extension of ksh). bash is the default shell on most Linux systems.
The Bourne Again Shell (bash), as its name implies, is an extension of the Bourne shell. bash is fully backward-compatible with the Bourne shell, but contains many enhancements and extra features that are not present in the Bourne shell. bash also contains many of the best features that exist in the C and Korn shells. bash has a very flexible and powerful programming interface, as well as a user-friendly command interface.
Why use bash instead of sh (the original Bourne shell)? The biggest drawback of the Bourne shell is the way that it handles user input. Typing commands into the Bourne shell can often be very tedious, especially if you are using it on a regular basis and typing in a large number of commands. bash provides several features that make entering commands much easier.
Often when you enter commands into bash (or any other shell), the complete text of the command is not necessary in order for the shell to be able to determine what you want it to do. For example, assume that the current working directory contains the following files and subdirectories:
News/ bin/ games/ mail/ samplefile test/
If you want to change directories from the current working directory to the test subdirectory, enter the command
cd test
Although this command works just fine, bash enables you to accomplish the same thing in a slightly different (and faster) way. Since test is the only file in the directory that begins with the letter t, bash should be able to figure out what you want to do after you simply type t:
cd t
After the letter is typed, the only thing that you could be referring to is the test subdirectory. To get bash to finish the command for you, press the Tab key:
cd t<tab>
When you do this, bash finishes the command and displays it on the screen. The command doesnt actually execute until you press the Enter key, which verifies that the command bash comes up with is the command that you really intend.
For short commands like this, you might not see very much value in making use of command-line completion. Using this feature may at first slow you down when typing short commands. After you get used to using command-line completion, though, and when the commands you enter get a little longer, you will wonder how anyone lived without this feature.
So what happens if more than one file in the directory begins with the letter t? It would seem that this would cause a problem if you wanted to use command-line completion. Lets see what happens when you have the following directory contents:
News/ bin/ mail/ samplefile test/ tools/ working/
Now you have two files in the directory that start with the letter t. Assuming that you still want to cd into the test subdirectory, how do you do that using command-line completion? If you type cd t<tab> as you did before, bash does not know which subdirectory you want to change to because the information you have given is not unique.
bash then beeps to notify you that it does not have enough information to complete the command. After beeping, bash leaves the command on the screen as it was entered. This enables you to enter more information without retyping what was already typed. In this case, you only need to enter an e and press the Tab key again. This gives bash enough information to complete the command on the command line for you to verify:
cd test
If instead you decide that you want to cd into the tools subdirectory, you can type:
cd to<tab>
This gives bash enough information to complete the command.
Whenever you press the Tab key while typing a command, bash tries to complete the command for you. If it cant complete the command, it fills in as much as it can and then beeps, notifying you that it needs more information. You can then enter more characters and press the Tab key again, repeating this process until bash displays the desired command.
Previous | Table of Contents | Next |