sh, for, case, if, while, \fB:\fP, \fB.\fP, break, continue, cd, eval, exec, exit, export, login, newgrp, read, readonly, set, shift, times, trap, umask, wait \- command language
is a command programming language
that executes commands read from a terminal
for the meaning of arguments to the shell.
is a sequence of non blank
separated by blanks (a blank is a
The first word specifies the name of the command to
Except as specified below
the remaining words are passed as arguments
The command name is passed as argument 0
of a simple-command is its exit status
if it terminates normally or 200+\fIstatus\fP if
it terminates abnormally (see
is a sequence of one or more
The standard output of each command but the last
to the standard input of the next command.
Each command is run as a separate process;
the shell waits for the last command to terminate.
is a sequence of one or more
and optionally terminated by
which is lower than that of
also have equal precedence.
A semicolon causes sequential execution; an ampersand causes
to be executed without waiting for it to finish.
following to be executed only if the preceding
returns a zero (non zero) value.
is either a simple-command
The value returned by a command is that of the
last simple-command executed in the command.
\fBfor \fIname\fR \*(OK\fBin \fIword\fR ...\*(CK \fBdo \fIlist \fBdone\fR
is set to the next word in the
Execution ends when there are no more words in the list.
\fBcase \fIword \fBin\fR \*(OK\fIpattern \fR\*(OK \fB\(or \fIpattern \fR\*(CK ... \fB) \fIlist \fB;;\fR\*(CK ... \fBesac\fR
associated with the first
The form of the patterns is
the same as that used for
\fBif \fIlist \fBthen \fIlist\fR \*(OK\fBelif \fIlist \fBthen \fIlist\fR\*(CK ... \*(OK\fBelse \fIlist\fR\*(CK \fBfi\fR
is executed and if it returns zero the
is executed and if its value is zero
\fBwhile \fIlist\fR \*(OK\fBdo \fIlist\fR\*(CK \fBdone\fR
command repeatedly executes the
and if its value is zero executes the
otherwise the loop terminates.
of the last executed command in the
the loop termination test.
are only recognized as the first word of a command
if then else elif fi case in esac for while until do done { }
The standard output from a command enclosed in
may be used as part or all
trailing newlines are removed.
.B Parameter substitution.
is used to introduce substitutable
Positional parameters may be assigned values by
Variables may be set by writing
$\fB\|{\fIparameter\fB\|}\fR
is a sequence of letters, digits or underscores (a
The value, if any, of the parameter is substituted.
The braces are required only when
is followed by a letter, digit, or underscore
that is not to be interpreted as part of its name.
is a digit then it is a positional parameter.
parameters, starting with
is set from argument zero when the shell
$\fB\|{\fIparameter\|\-word\|\fB}\fR
is set then substitute its value;
$\fB\|{\fIparameter\|\(eq\|word\|\fB}\fR
is not set then set it to
the value of the parameter is then substituted.
Positional parameters may not be assigned to
$\fB\|{\fIparameter\|?\|word\|\fB}\fR
is set then substitute its value;
is omitted then a standard message is printed.
$\fB\|{\fIparameter\|\(plword\|\fB}\fR
otherwise substitute nothing.
is not evaluated unless it is
to be used as the substituted string.
are automatically set by the shell.
The number of positional parameters in decimal.
Options supplied to the shell on invocation or by
The value returned by the last executed command
The process number of this shell.
The process number of the last background command invoked.
are used but not set by the shell.
The default argument (home directory) for the
The search path for commands (see
If this variable is set to the name of
a mail file then the shell informs the user of
the arrival of mail in the specified file.
Primary prompt string, by default `$ '.
Secondary prompt string, by default `> '.
Internal field separators,
After parameter and command substitution,
any results of substitution are scanned for internal field separator
characters (those found in
and split into distinct arguments where such characters are found.
Explicit null arguments ("" or \'\') are retained.
that have no values) are removed.
Following substitution, each command word is scanned for
If one of these characters appears
then the word is regarded as a pattern.
The word is replaced with alphabetically sorted file names that match the pattern.
If no file name is found that matches the pattern then
the word is left unchanged.
at the start of a file name
or immediately following a
must be matched explicitly.
Matches any string, including the null string.
Matches any single character.
Matches any one of the characters
A pair of characters separated by
character lexically between the pair.
The following characters have a special meaning to the shell
and cause termination of a word unless quoted.
\fB; & ( ) \(or \*(LT \*(GT newline space tab\fP
All characters enclosed between a pair of quote marks (\fB\'\|\'\fP),
parameter and command substitution occurs and
the shell prompts with the value of
before reading a command.
If at any time a newline is typed and further input is needed
to complete a command then the secondary prompt
Before a command is executed its input and output
may be redirected using a special notation interpreted by the shell.
The following may appear anywhere in a simple-command
or may precede or follow a
and are not passed on to the invoked command.
Substitution occurs before
as standard input (file descriptor 0).
as standard output (file descriptor 1).
If the file does not exist then it is created;
otherwise it is truncated to zero length.
If the file exists then output is appended (by seeking to the end);
otherwise the file is created.
The shell input is read up to a line the same as
The resulting document becomes
is quoted then no interpretation
is placed upon the characters of the document;
otherwise, parameter and command substitution occurs,
is used to quote the characters
and the first character of
The standard input is duplicated from file descriptor
Similarly for the standard output using \*(GT\|.
The standard input is closed.
Similarly for the standard output using \*(GT\|.
If one of the above is preceded by a digit
file descriptor created is that specified
(instead of the default 0 or 1).
creates file descriptor 2 to be a duplicate
If a command is followed by
then the default standard input
Otherwise, the environment for the execution of a command contains the
file descriptors of the invoking shell as modified by input
is a list of name-value pairs that is passed to
an executed program in the same way as a normal argument list;
The shell interacts with the environment in several ways.
On invocation, the shell scans the environment
giving it the corresponding value.
Executed commands inherit the same environment.
If the user modifies the values of these
none of these affects the environment
command is used to bind the shell's
The environment seen by any executed command is thus composed
of any unmodified name-value pairs originally inherited by the shell,
plus any modifications or additions,
all of which must be noted in
may be augmented by prefixing it with one or more assignments to
Thus these two lines are equivalent
(export TERM; TERM=450; cmd args)
keyword arguments are placed in the environment,
even if the occur after the command name.
The following prints `a=b c' and `c':
The INTERRUPT and QUIT signals for an invoked
command are ignored if the command is followed by
otherwise signals have the values
inherited by the shell from its parent.
Each time a command is executed the above substitutions
Except for the `special commands' listed below a new
an attempt is made to execute the command via an
defines the search path for
the directory containing the command.
Each alternative directory name is separated by
If the command name contains a / then the search path
Otherwise, each directory in the path is
searched for an executable file.
If the file has execute permission but is not an
it is assumed to be a file containing shell commands.
A subshell (i.e., a separate process) is spawned to read it.
A parenthesized command is also executed in
The following commands are executed in the shell process
and except where specified
no input output redirection is permitted for such commands.
No effect; the command does nothing.
Read and execute commands from
is used to find the directory containing
\fBbreak\fR \*(OK\fIn\fR\*(CK
\fBcontinue\fR \*(OK\fIn\fR\*(CK
Resume the next iteration of the enclosing
is specified then resume at the
\fBcd\fR \*(OK\fIarg\fR\*(CK
Change the current directory to
\fBeval\fR \*(OK\fIarg \fR...\*(CK
The arguments are read as input
and the resulting command(s) executed.
\fBexec\fR \*(OK\fIarg \fR...\*(CK
the arguments is executed in place of this shell
without creating a new process.
Input output arguments may appear and if no other
arguments are given cause the shell input
\fBexit\fR \*(OK\fIn\fR\*(CK
Causes a non interactive shell to exit
with the exit status specified by
is omitted then the exit status is that of the last command executed.
(An end of file will also exit from the shell.)
\fBexport\fR \*(OK\fIname\fR ...\*(CK
The given names are marked
for automatic export to the
of subsequently-executed commands.
If no arguments are given then a list of
exportable names is printed.
\fBlogin\fR \*(OK\fIarg\fR ...\*(CK
Equivalent to `exec login arg ...'.
\fBnewgrp\fR \*(OK\fIarg \fR...\*(CK
Equivalent to `exec newgrp arg ...'.
One line is read from the standard input;
successive words of the input are assigned to the
with leftover words to the last variable.
The return code is 0 unless the end-of-file is encountered.
\fBreadonly\fR \*(OK\fIname \fR...\*(CK
The given names are marked readonly and
the values of the these names may not be changed
by subsequent assignment.
If no arguments are given then a list
of all readonly names is printed.
\fBset\fR \*(OK\fB\-eknptuvx\fR \*(OK\fIarg \fR...\*(CK\*(CK
If non interactive then exit immediately if a command fails.
All keyword arguments are placed in the environment for a command,
not just those that precede the command name.
Read commands but do not execute them.
Exit after reading and executing one command.
Treat unset variables as an error when substituting.
Print shell input lines as they are read.
Print commands and their arguments as they are executed.
These flags can also be used upon invocation of the shell.
The current set of flags may be found in
Remaining arguments are positional
parameters and are assigned, in order, to
If no arguments are given then the values
of all names are printed.
The positional parameters from
Print the accumulated user and system times for
processes run from the shell.
\fBtrap\fR \*(OK\fIarg\fR\*(CK \*(OK\fIn\fR\*(CK ...
is a command to be read and executed when the shell
the trap is set and once when the trap
Trap commands are executed in order of signal number.
is absent then all trap(s)
to their original values.
string then this signal is ignored by the shell and by invoked commands.
otherwise upon receipt of signal
with no arguments prints a list
of commands associated with each signal number.
\fBumask \fR[ \fInnn\fR ]
The user file creation mask is set to
is omitted, the current value of the mask is printed.
\fBwait\fP \*(OK\fIn\fP\*(CK
Wait for the specified process and
report its termination status.
is not given then all currently active child processes are waited for.
The return code from this command is that of
If the first character of argument zero is
.BR \s-2$HOME\s0/.\|profile ,
Commands are then read as described below.
The following flags are interpreted by the shell
then commands are read from the standard input.
Shell output is written to
if the shell input and output are attached to a terminal (as told by
In this case the terminate signal
is ignored (so that `kill 0'
does not kill an interactive shell) and the interrupt signal
SIGINT is caught and ignored
In all cases SIGQUIT is ignored by the shell.
The remaining flags and arguments are described under the
Errors detected by the shell, such as syntax errors
to return a non zero exit status.
If the shell is being used non interactively
then execution of the shell file is abandoned.
Otherwise, the shell returns the exit status of
the last command executed (see also
IF \*(LT\*(LT is used to provide standard input to an asynchronous
the shell gets mixed up about naming the input document.
A garbage file /tmp/sh* is created, and the shell complains about
not being able to find the file by another name.