P1: JDW
UNIX WL040/Bidgoli-Vol III-Ch-41 August 13, 2003 17:26 Char Count= 0
CORECOMPONENTS 501The net effect of this strategy was that on multiproces-
sor computers, jobs could be completed faster and pro-
grammed with much greater ease. Users working at the
shell could benefit from pipes as well. For example, the
commandls -la/ usr/bin| grep mark | awk '{sum +
= $5; print} END {print sum}'will generate a detailed directory listing of the/usr/bin di-
rectory, and print out only mark’s files (literally any line
that contains the lettersm, a, r,andkconsecutively in that
order) and then print out as the final output of the pipeline
the total number of bytes in the selected files. It will do
this by piping the output of the ls command into the grep
command, and then piping the result of that stream out
to the awk command. The filesize of a given file is stored
in the 5th field ($5) of the long (-l) ls listing output. In the
above example, grep and awk are both filters. The ‘|’ char-
acter is the pipe command that creates a pipe between
filters. Imagine asking the Microsoft Windows Explorer
to provide you with that information on some arbitrary
(i.e., user-defined) subset of files in a directory.
Using pipes allows the developer to write many small
generic programs (called “filters”) that focus on doing one
thing well and then to be able to arrange them in vari-
ous configurations that produce different and powerful
user-defined results. Any program that is written to ac-
cept ASCII input and write ASCII output over a pipe is
known as a filter.CORE COMPONENTS
Editors
Unix has a long list of editors, beginning with Ken
Thompson’s original ed line editor. The two most pop-
ular editors on a Unix system are BSD’s vi editor and
Stallman’s emacs editor. Other editors have come along
in the meantime and are available on different Unix ver-
sions. Among these are the PICO editor (originated with
the Pine mail program), nedit, and the various CDE-based
editor versions, usually called dtpad or something similar.
(CDE stands for the Common Desktop Environment and
is a graphical version of Unix based on MIT’s X Windows
graphical user interface. CDE is available for most com-
mercial Unix versions.) By far, the two most popular edi-
tors on a Unix system are vi and emacs. Every Unix system
can be expected to offer the vi editor out of the box.vi
Vi (pronounced “vee-eye”) is a command mode editor,
meaning that it is a shockingly far cry from the common
WYSIWYG (What You See Is What You Get) word proces-
sors of today (and often much more powerful). Vi has two
primary modes, command mode and edit mode. Users
type their documents in an edit mode and modify them
by issuing commands in command mode.
There are numerous commands to operate on text in vi,
and they all operate from command mode. For example,
to swap two characters (say “no”), the user would posi-
tion the cursor on the n and then issue the command
“xp” (x for cut and p for paste); the text would thenread “on”, with the two adjacent characters swapped.
The mode commands include “i,” which enters into in-
sert mode; “o,” which opens up a line under the cursor;
“O,” which opens a new line above the cursor; and “ESC,”
which exits an edit mode. Although for many users it is
difficult to get used to vi, a competent vi user can com-
pletely transform a large file of text before a Windows
notepad user has even navigated the Start menu, launched
the notepad program, and highlighted the first bit of text
with his mouse.emacs
The emacs editor is radically different from vi in that it is
not a modal editor but rather an editing environment. It
is powerful and can be used as a programmer’s editor sup-
ported by special modes for dozens of programming lan-
guages. These modes provide various capabilities, such as
colorized syntax highlighting and pretty formatting that
can be customized by the emacs user.
Emacs was originally written for Unix by James
Gosling (of the Java Programming Language fame) and
offers an environment in the sense that users can do many
different things within the emacs editor. For example,
users can of course edit text, but they can also read and
write e-mail, read and post messages through usenet, navi-
gate and display directories and files in the file system—
they can even play games with intriguing names such as
“Zippy the Pinhead” and “Doctor” (a “psychiatrist” who
will diagnose all one’s mental problems—free of charge).
You can do so many things fromwithinemacs that before
windowing environments many Unix users lived their en-
tire day within emacs, rarely exiting out to the shell.Command Interface: The Shell
Unix interfaces with the user through a program called
the shell. A shell is a command processor that prompts the
user for input and interprets and then executes the com-
mand entered on the user’s behalf. A shell is just another
user program. It provides the main interface between the
Unix system and the user. As with most things in Unix,
the user has a number of shells from which to choose. A
user can choose to work within the Bourne shell (sh), the
Korn shell (ksh), the C shell (csh), and a variety of newer
shells, including the z shell (zsh), the Bash shell (Bourne
Again Shell, bash), and the modern C shell (tcsh).
Different shells have different capabilities, but most
shells draw from two primary heritages: the original
Bourne shell from AT&T Version 7 and the original C
shell from BSD (see Figure 1). System V derivatives have
usually followed the Bourne shell lineage, and most mod-
ern Unix systems come with the Korn shell or original
Bourne shell as the default user shell. Users can gener-
ally change their shell preference, however, and the chsh
(change shell) command will allow users to select another
one. The traditional prompt for Bourne derivatives is the
dollar sign: $. The traditional prompt for C Shell deriva-
tives is the percent sign: ‘%’. This will also be an indication
of what type of shell a user is running.
Because a shell is just another user program, from one
shell, a user can start up another shell. A user can run a
C shell session from a Korn shell, for example. A user can