A simple command is a sequence of optional parameter assignments followed by blank-separated words, with optional redirections interspersed. The first word is the command to be executed, and the remaining words, if any, are arguments to the command. If a command name is given, the parameter assignments modify the environment of the command when it is executed. The value of a simple command is its exit status, or 128 plus the signal number if terminated by a signal.
A pipeline is a sequence of one or more commands separated by
|
or |&
. |&
is shorthand for 2>&1 |
. The
standard output of each command is connected to the standard input of
the next command in the pipeline.
If a pipeline is preceded by coproc
, it is executed as a
coprocess; a two-way pipe is established between it and the parent
shell. The shell can read from or write to the
coprocess by means of the >&p
and <&p
redirection operators.
The value of a pipeline is the value of the last command. If a pipeline
is not preceded by !
, the value of that pipeline is the logical
NOT
of the value of the last command.
A sublist is a sequence of one or more pipelines separated by
&&
or ||
. If two pipelines are separated by &&
,
the second pipeline is executed only if the first is successful (returns
a zero value). If two pipelines are separated by ||
, the second
is executed only if the first is unsuccessful (returns a nonzero
value). Both operators have equal precedence and are left
associative.
A list is a sequence of zero or more sublists separated by, and
optionally terminated by, ;
, &
, &|
, &!
,
or a newline. Normally the shell waits for each list to finish before
executing the next one. If a list is terminated by a &
, &|
,
or &!
, the shell executes it in the background, and does not wait
for it to finish.
A simple command may be preceded by a precommand modifier which will
alter how the command is interpreted. These modifiers are shell builtin
commands with the exception of nocorrect
which is a reserved word.
-
-
prepended to its argv[0]
string.
noglob
nocorrect
exec
command
A complex command in zsh is one of the following:
if list then list [ elif list then list ] ... [ else list ] fi
if list
is executed, and, if it returns a zero exit
status, the then list
is executed. Otherwise, the
elif list
is executed and, if its value is zero, the
then list
is executed. If each elif list
returns nonzero, the else list
is executed.
for name [ in word ... term ] do list done
;
. Expand the list of
words, and set the parameter name to each of them in turn,
executing list each time. If the in word
is omitted, use
the positional parameters instead of the words.
while list do list done
do list
as long as the while list
returns a zero exit status.
until list do list done
do list
as long as until list
returns a
nonzero exit status.
repeat word do list done
case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
select name [ in word ... term ] do list done
;
.
Print the set of words, each preceded by a number. If the
in word
is omitted, use the positional parameters. The
PROMPT3
prompt is printed and a line is read from standard input.
If this line consists of the number of one of the listed words,
then the parameter name is set to the word corresponding to
this number. If this line is empty, the selection list is printed
again. Otherwise, the value of the parameter name is set to null.
The contents of the line read from standard input is saved in the
parameter REPLY
. list is executed for each selection until
a break or end-of-file is encountered.
( list )
trap
builtin
are reset to their default values while executing list
.
{ list }
function word ... [ () ] [ term ] { list }
word ... () [ term ] { list }
word ... () [ term ] command
;
.
Define a function which is referenced by any one of word.
Normally, only one word is provided; multiple words are
usually only useful for setting traps. The body of the function is the
list between the {
and }
.
See section Functions.
time [ pipeline ]
TIMEFMT
parameter. If pipeline is omitted, print statistics about the
shell process and its children.
[[ exp ]]
Many of zsh's complex commands have alternate forms. These particular
versions of complex commands should be considered deprecated and may be
removed in the future. The versions in the previous section should be
preferred instead. The short versions below only work if
sublist
is of the form { list }
or if the
NO_SHORT_LOOPS
option is not set.
if list { list } [ elif list { list } ] ... [ else { list } ]
if
.
if list sublist
for name ( word ... ) sublist
for
.
for name [ in word ... term ] sublist
;
. Another short form of
for
.
foreach name ( word ... ) list end
for
.
while list { list }
while
.
until list { list }
until
.
repeat word sublist
repeat
.
case word { [ [(] pattern [ | pattern ] ... ) list ;; ] ... }
case
.
select name [ in word term ] sublist
;
. A short form of
select
.
The following words are recognized as reserved words when used as the
first word of a command unless quoted or disabled using disable -r
:
do
done
esac
then
elif
else
fi
for
case
if
while
function
repeat
time
until
select
coproc
nocorrect
foreach
end
!
[[
{
}
Additionally }
is recognized in any position if the
IGNORE_BRACES
option is not set.
In non-interactive shells, or in interactive shells with the
INTERACTIVE_COMMENTS
option set, a word beginning with the third
character of the histchars
parameter (#
by default) causes
that word and all the following characters up to a newline to be
ignored.
Every token in the shell input is checked to see if there is an alias
defined for it. If so, it is replaced by the text of the alias if it is
in command position (if it could be the first word of a simple command),
or if the alias is global. If the text ends with a space, the next word
in the shell input is treated as though it were in command position for
purposes of alias expansion. An alias is defined using the alias
builtin; global aliases may be defined using the `-g' option to
that builtin.
Alias substitution is done on the shell input before any other substitution except history substitution. Therefore, if an alias is defined for the word `foo', alias substitution may be avoided by quoting part of the word, e.g. `\foo'. But there is nothing to prevent an alias being defined for `\foo' as well.
A character may be quoted (that is, made to stand for itself) by
preceding it with a \
. \
followed by a newline is
ignored. All characters enclosed between a pair of single quotes
(''
) are quoted, except the first character of histchars
(!
by default). A single quote cannot appear within single
quotes. Inside double quotes (""
), parameter and command
substitution occurs, and \
quotes the characters \
,
`
, "
, and $
.
Go to the first, previous, next, last section, table of contents.