How the shell works
Your login shell reads its standard input from your terminal, and
sends its standard output and standard error back to your terminal
unless you tell it to send them elsewhere. (See
``More about redirecting input and output''
for more information on these streams.) The shell is line
oriented; it does not process your commands until you press
<Enter> to indicate the end of a line. You can correct your typing as
you go. Different shells provide different facilities for editing
your commands, but they generally recognize <Bksp> or <Del> as the
keystroke to delete the previous character.
When you press <Enter>, the shell interprets the line you have entered
before it executes the commands on that line. The steps it runs
through are as follows:
The shell splits the line into tokens. A token is a
command, variable, or other symbol recognized by the shell. It
continues to build up a sequence of tokens until it comes to a
reserved word (a shell internal command that governs the
flow of control of a shell script), function name, or
operator (a symbol denoting a pipe, a logical condition, a
command separator, or some other operation that cannot be carried
out until the preceding command is evaluated).
The shell organizes the tokens into three categories:
I/O redirection; commands that determine where the input
or output of a program are directed. For example, in the following
command line, the text ``>listfile'' is interpreted as an output
redirection, which is later applied to the preceding command:
ls -al >listfile
Variable assignment; the shell can recognize commands that assign
a value to a variable.
Miscellaneous commands; other tokens are checked to see if they are
aliases. The first word is checked. If it is an alias, it is
replaced by the original meaning of the alias; if it is not an
alias, or if it is followed by a whitespace character before the
next word, the process of alias checking is repeated until no more
words remain (or until an alias has been detected that is not
followed by a space).
The commands may then be executed, either as internal shell commands
(that cause the shell itself to take some action) or, if they are
not internal commands, as external programs (if the shell can locate
an executable file of that name).
How the shell executes commands
How aliases are executed
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003