Chapter 4: The Command Shell


As you have seen, a large part of using UNIX is issuing commands. When you enter a command, you are dealing with the shell, the interface through which you control the resources of the UNIX operating system. The shell provides many of the features that make the UNIX System a uniquely powerful and flexible environment. It is a command interpreter, a programming language, and more.

This chapter describes the basic features that the shell provides, focusing on how it interprets your commands and how you can use its features to simplify your interactions with the UNIX System. It explains what the shell does for you, how it works, and how you use it to issue commands and to control how they are run. You will learn all of the basic shell commands and features that you need to understand in order to use the UNIX System effectively and confidently

The shell includes many features that allow you to customize your working environment. You can use shell variables and aliases to simplify common tasks, which will be covered in this chapter. In addition, you can use the shell’s command language as a high-level programming language to create programs called scripts. Shell scripting will be described later, in Chapter 20.

There are actually several different shell programs, but they all provide the same basic capabilities. This chapter covers the most common shells: sh (the original Bourne shell), csh and tcsh (the C shell and extended C shell), ksh (the Korn shell), and bash (the Bourne Again shell). It describes the features that you need to know to use any of these shells, as well as explaining the enhancements each of the shells has to offer, and how they differ from each other.

The Common Shells

The original UNIX System shell, sh, was written by Steve Bourne, and as a result it is known as the Bourne shell. Because it was the first, the Bourne shell lacks many enhancements common to the later shells. It can still be useful for certain tasks (such as scripting, described in Chapter 20), but almost all users will prefer one of the newer shells for entering commands.

The C shell, csh, was the first attempt to enhance the original Bourne shell. The syntax was strongly influenced by the C programming language. The C shell introduced the concepts of a command history list, job control, and aliases. However, like sh, it lacks some important features of later shells. A common complaint about csh is that the new syntax is not compatible with the Bourne shell, and so some scripts may not work properly in csh.

The extended C shell, tcsh, has replaced csh entirely on some versions of UNIX (including Linux). It retains all the features of csh and adds command-line editing (a very important shell feature) and history completion. It is one of the more popular shells, although like csh it has been criticized for not being compatible with the Bourne shell.

The Korn shell, ksh, was developed at AT&T Bell Laboratories by David Korn. Unlike the C shell, the Korn shell has a syntax compatible with sh. Like tcsh, ksh includes a command history list, job control, aliases, and command-line editing. The Korn shell was until recently proprietary to AT&T, although it can now be downloaded for free.

The Bourne Again Shell, bash, is part of the GNU project. It extends ksh further, while remaining compatible with the original Bourne shell syntax, and adds a few features from tcsh as well. bash is the default shell in Linux and may be the most popular shell today On some systems, the command sh will run bash instead.

There are other shells out there, including rc, which is a new shell similar to the original Bourne shell, pdksh, a public domain version of the Korn shell, and zsh, which adds even more features to bash. To see if your system includes a particular shell, check if it has a man page (e.g., try man ksh), or read the file /etc/shells, which is a list of the shells installed on the system. The section “Sources and Sites” at the end of this chapter lists the web sites where the various shells may be obtained, so that you can download and install your preferred shell if it didn’t come with your system.




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net