Table of Contents
NAME
zsh - the Z shell
SYNOPSIS
zsh [ ±options ] [ ±o option ] ...
[ -c string ] [ arg ... ]
SHELL GRAMMAR
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.
If a simple command is preceded by the word exec, it is
executed in the parent shell without forking. If preceded by
command, the command word is taken to be the name of an
external command, rather than a shell function or builtin. If preceded
by noglob, filename generation is not performed on any of the
words. If preceded by a -, the command is executed with a - prepended
to its argv[0] string. If preceded by nocorrect,
spelling correction is not done on any of the words.
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.
The value of a pipeline is the value of the last command. If a
pipeline is preceded by a !, the value of that pipeline is the
logical NOT of the value of the last command.
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.
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 one 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 &, the shell executes it in
the background, and does not wait for it to finish.
A complex command is one of the following:
-
for name [ in word ... ]
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.
- for name [ in word ... ] ; sublist
- This is a shorthand for for. Though it may cause confusion, it
is included for convenience; its use in scripts is discouraged, unless
sublist is a command of the form { list }.
- foreach name ( word ... )
list
end
- Another form of for.
-
for name in word ...
{
list
}
- Another form of for.
-
for name ( word ... ) {
list}
-
Another form of for: this requires the option CSH_JUNKIE_PAREN.
-
for name ( word ... ) sublist
-
Another form of for: this also requires the option
CSH_JUNKIE_PAREN.
-
select name [ in word ... ]
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 endof-file is
encountered.
-
select name [ in word ] ; sublist
- A short form of select.
-
case word in [ pattern ) list ;; ]
... esac
- Execute the list associated with the first
pattern that matches word, if any. The form of the
patterns is the same as that used for filename generation. See
Filename Generation below.
-
case word { [ pattern ) list ;; ]
... }
- Another form of case.
- if list
then list
[ elif list ; then list ] ...
[ else list ]
fi
- The 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.
- if ( list ) sublist
-
A short form of if: this requires the option CSH_JUNKIE_PAREN.
- if ( list ) {
list
} elif ( list ) {
list
} ... else {
list
}
-
An alternative form of if. The parentheses surrounding
list can be omitted if the only command in the list is a
conditional expression of the form [[ exp ]] (see below). This form
also requires CSH_JUNKIE_PAREN.
-
while list
do list
done
- Execute the do list as long as the while
list returns a zero exit status.
-
while ( list ) { list }
-
An alternative form of while: this requires the option
CSH_JUNKIE_PAREN.
-
until list
do list
done
- Execute the do list as long as until
list returns a nonzero exit status.
-
repeat word
do list
done
- word is expanded and treated as an arithmetic expression,
which must evaluate to a number n. list is then executed
n times.
-
repeat word sublist
- This is a short form of repeat.
-
( list )
- Execute list in a subshell.
-
{ list }
- Execute list.
-
function word [ () ] ... { list } word
... () { list }
word ... () sublist
-
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
FUNCTIONS below.
-
time [ pipeline ]
- The pipeline is executed, and timing statistics are
reported on the standard error in the form specified by the
TIMEFMT parameter. If pipeline is omitted, print
statistics about the shell process and its children.
-
[[ exp ]]
- Evaluates the conditional expression exp and return a zero
exit status if it is true. See Conditional Expressions below
for a description of exp.
Mark D. Borges