Go to the first, previous, next, last section, table of contents.
A simple command is a string of normal or I/O words terminated by a newline or one of the other special words, and not starting with a reserved word. Each I/O word is combined with the following word (which must be a normal word) to form an I/O directive. Then all leading assignment words or, if the `k' flag is set, all assignment words are collected to form a local environment. The remaining words form the body of the command. A number of substitutions (described below) are performed on these words before the command, determined by the first word in the body, is executed.
A
pipeline
is a number of
commands,
simple
or
structured
(see
Structured Commands
below),
separated by the pipe (|)
word.
These commands are run simultaneously with the standard output of
each command but
the last connected to the standard input of the next command by the use of a
pipe
(see pipe(2)).
A
task
is a number of pipelines separated by either
&&
or
||.
In order to describe the meaning of these separators, it is more convenient to
describe a
task
as being either a
pipeline
or a
task
followed by one of
&&
or
||
and then a
pipeline.
A
pipeline
following a
&&
is executed only if the preceding
task
succeeded.
A
pipeline
following a
||
is executed only if the preceding
task
failed
(see
Execution
for the meaning of success and failure).
Finally a
command list
is a number of
tasks
each terminated by a semicolon
(;),
an ampersand
(&),
or a newline.
The
&
causes the
task
to be run in the
background
so that it does not respond to keyboard signals (such as
INTERRUPT
or
QUIT)
and that the shell does not wait for it to complete before proceeding.
A semicolon
(;)
or a newline causes the
task
to run in the
foreground
and the shell waits for the completion of the task before the next command
is executed.
A special type of command list is a job in which only the last task is terminated by a newline. When commands are being read from a file or the terminal, one job is read and executed at a time.
The following structured commands are particularly useful for writing
shell scripts
--- programs which are interpreted by the shell.
They can all be followed by I/O redirection directives that will affect every
subcommand within the whole.
Where
list
appears below, the list must be terminated with a semicolon
(;),
ampersand
(&)
or newline except where it is followed by a
special word
as is the case in the
case
and
(
statements.
Also where a semicolon is shown, a newline may be used instead.
if list then list [elif list then list ...] [else list] fi
then
otherwise perform the
elif
or
else
parts if they exist.
ifnot
and
elifnot
may be used in place of
if
and
elif
to invert the sense of the test.
for name [in word ...] ; do list done
in
clause is omitted) and the
list
is executed.
If present, the word list is subjected to that same sequence of substitutions
as words in a
simple command.
while list do list done
until list do list done
while
except that looping continues until first list succeeds.
case word in pattern[ | pattern]) list ;; ... esac
{ list }
( list )
Functions are defined with a syntax vaguely reminiscent of C. More precisely:
function-name()
{
statement-list
}
or, alternately
function function-name()
{
statement-list
}
Go to the first, previous, next, last section, table of contents.