sh \*- shell (command interpreter)
[ name [ arg1 ... [ arg9 ] ] ]
is the standard command interpreter.
It is the program which reads and arranges the execution of
the command lines typed by most users.
It may itself be called as a command to interpret
Before discussing the arguments to the Shell
used as a command, the structure of command
lines themselves will be given.
Each command is a sequence of non-blank command arguments
first argument specifies the name of a command to be
executed. Except for certain types of special
arguments discussed below, the arguments
other than the command name are passed
without interpretation to the invoked
If the first argument is the name of an executable
otherwise the string `/bin/' is prepended to the argument.
(In this way most standard commands,
which reside in `/bin', are found.)
If no such command is found,
the string `/usr' is further prepended
(to give `/usr/bin/command') and another attempt
is made to execute the resulting
(Certain lesser-used commands
the `/usr/bin' file exists, but is not
executable, it is used by the Shell as
That is to say it is executed
as though it were typed from the console.
If all attempts fail, a diagnostic is printed.
One or more commands separated by `\*v' or `^' constitute a
The standard output of each command but the last in a pipeline
as the standard input of the next command.
Each command is run as a separate process, connected
by pipes (see pipe(II)) to its neighbors.
A command line contained in
parentheses `( )' may appear in place of a simple command
as an element of a pipeline.
more pipelines separated, and perhaps terminated by `\fB;\fR' or `&'.
The semicolon designates sequential execution.
The ampersand causes the preceding pipeline to be executed
without waiting for it to finish.
The process id of such a pipeline is reported, so that
it may be used if necessary for a subsequent
.bd "Termination Reporting."
If a command (not followed by `&') terminates abnormally,
(All terminations other than exit and interrupt
are considered abnormal.)
Termination reports for commands followed by `&'
are given upon receipt of the first
command subsequent to the termination of
The following is a list of the abnormal
If a core image is produced,
`\*- Core dumped' is appended to the appropriate message.
.bd "Redirection of I/O."
There are three char
\ 6ac
\ 6ter sequences that cause the immediately following string
to be interpreted as a special argument to the Shell itself.
the arguments of a simple command, or before or after
a parenthesized command list, and is associated with that
An argument of the form `<arg' causes the file
to be used as the standard input file of the associated command.
An argument of the form `>arg' causes file `arg' to be used
as the standard output file for the associated command.
`Arg' is created if it did not exist, and in any case is truncated
An argument of the form `>>arg' causes file `arg' to be used as the
standard output for the associated command. If `arg'
did not exist, it is created; if it did exist,
the command output is appended to the file.
For example, either of the command lines
ls >junk; cat tail >>junk
creates, on file `junk', a listing of the working directory, followed immediately
by the contents of file `tail'.
Either of the constructs `>arg' or `>>arg'
associated with any but the last command of a pipeline
is ineffectual, as is `<arg' in any but the first.
.bd "Generation of argument lists."
If any argument contains any of the char
\ 6ac
\ 6ters `?',
`*' or `[', it is treated specially as follows.
The current directory is searched for files which
The char
\ 6ac
\ 6ter `*' in an argument matches any string of char
\ 6ac
\ 6ters
in a file name (including the null string).
The character `?' matches any
single char
\ 6ac
\ 6ter in a file name.
Square brackets `[...]' specify
a class of characters which
matches any single file-name character in the class.
each ordinary character is taken
to be a member of the class.
A pair of characters separated by `\*-' places
each character lexically greater than or equal to
the first and less than or equal to the second
Other characters match only the same character in
For example, `*' matches all file names;
`?' matches all one-char
\ 6ac
\ 6ter file names; `[ab]*.s' matches
all file names beginning with `a' or `b' and ending with `.s';
`?[zi\*-m]' matches all two-character file names ending
with `z' or the letters `i' through `m'.
If the argument with `*' or `?' also contains a `/', a slightly
different procedure is used: instead of the current directory,
the directory used is the one obtained
by taking the argument up to the last `/' before a `*' or `?'.
The matching process matches the remainder of the argument
after this `/' against the files in the derived directory.
For example: `/usr/dmr/a*.s' matches
all files in directory `/usr/dmr' which begin
with `a' and end with `.s'.
In any event, a list of names is obtained which match
the argument. This list is sorted into alphabetical order,
and the resulting sequence of arguments replaces the
single argument containing the `*', `[', or `?'.
The same process is carried out for each argument
and finally the command is called with the resulting list of
For example: directory /usr/dmr contains the files
a1.s, a2.s, ..., a9.s. From any directory, the command
/usr/dmr/a1.s, /usr/dmr/a2.s, ...
The char
\ 6ac
\ 6ter `\\' causes the immediately following char
\ 6ac
\ 6ter
to lose any special meaning it may have to the Shell; in this
way `<', `>', and other char
\ 6ac
\ 6ters meaningful to the
Shell may be passed as part of arguments.
A special case of this feature allows the continuation of commands
onto more than one line: a new-line preceded by `\\' is translated
Sequences of char
\ 6ac
\ 6ters enclosed in double (") or single (\*a)
quotes are also taken literally.
ls \*v pr \*-h "My directory"
causes a directory listing to be produced
printed with the heading `My directory'.
Quotes permit the inclusion of blanks in
the heading, which is a single argument to
When the Shell is invoked as a command, it has additional
string processing capabilities.
Recall that the form in which the Shell is invoked is
sh [ name [ arg1 ... [ arg9 ] ] ]
is the name of a file which will be read and
interpreted. If not given, this subinstance of the Shell
will continue to read the standard input file.
In command lines in the file
character sequences of the form `$n', where
\fIn\fRth argument to the invocation
An end-of-file in the Shell's input causes it to exit.
A side effect of this fact means that the way to
log out from UNIX is to type an EOT.
The following commands are treated specially by the Shell.
spawning a new process by executing
/bin/login without creating a new process.
is done without spawning a new process by
is done by manipulating the arguments
`\fB:\fR' is simply ignored.
.bd "Command file errors; interrupts."
Any Shell-detected error, or an interrupt signal,
during the execution of a command file
causes the Shell to cease execution of that file.
Process that are created with a `&' ignore interrupts.
Also if such a process has not redirected its
its input is automatically redirected to the
zero length file /dev/null.
which interprets `*', `?', and `['.
/dev/null as a source of end-of-file.
`The UNIX Time-sharing System',
which gives the theory of operation of the
chdir(I), login(I), wait(I), shift(I)
When output is redirected,
particularly to make a multicommand
sent down the pipe and are sometimes
Not all components of a pipeline swawned with `&'