zshexpn.1   [plain text]

.TH "ZSHEXPN" "1" "December 20, 2010" "zsh 4\&.3\&.11"
zshexpn \- zsh expansion and substitution
.\" Yodl file: Zsh/expn.yo
The following types of expansions are performed in the indicated order in
five steps:
.PD 0
\fIHistory Expansion\fP
This is performed only in interactive shells\&.
\fIAlias Expansion\fP
Aliases are expanded immediately before the command line is parsed as
under Aliasing in \fIzshmisc\fP(1)\&.
.PD 0
\fIProcess Substitution\fP
.PD 0
\fIParameter Expansion\fP
.PD 0
\fICommand Substitution\fP
.PD 0
\fIArithmetic Expansion\fP
\fIBrace Expansion\fP
These five are performed in one step in left\-to\-right fashion\&.  After
these expansions, all unquoted occurrences of the characters `\fB\e\fP\&',
`\fB\&'\fP' and `\fB"\fP' are removed\&.
\fIFilename Expansion\fP
If the \fBSH_FILE_EXPANSION\fP option is set, the order of expansion is
modified for compatibility with \fBsh\fP and \fBksh\fP\&.  In that case
\fIfilename expansion\fP is performed immediately after \fIalias expansion\fP,
preceding the set of five expansions mentioned above\&.
\fIFilename Generation\fP
This expansion, commonly referred to as \fBglobbing\fP, is always done last\&.
The following sections explain the types of expansion in detail\&.
History expansion allows you to use words from previous command
lines in the command line you are typing\&.  This simplifies spelling
corrections and the repetition of complicated commands or arguments\&.
Immediately before execution, each command is saved in the history list,
the size of which is controlled by the \fBHISTSIZE\fP parameter\&.  The one
most recent command is always retained in any case\&.  Each saved command in
the history list is called a history \fIevent\fP and is assigned a number,
beginning with 1 (one) when the shell starts up\&.  The history number that
you may see in your prompt (see
EXPANSION OF PROMPT SEQUENCES in \fIzshmisc\fP(1)) is the number that is to be assigned to the \fInext\fP command\&.
.SS "Overview"
A history expansion begins with the first character of the \fBhistchars\fP
parameter, which is `\fB!\fP\&' by default, and may occur anywhere on the
command line; history expansions do not nest\&.  The `\fB!\fP\&' can be escaped
with `\fB\e\fP\&' or can be enclosed between a pair of single quotes (\fB''\fP)
to suppress its special meaning\&.  Double quotes will \fInot\fP work for
this\&.  Following this history character is an optional event designator
(see the section `Event Designators\&') and then an optional word
designator (the section `Word Designators\&'); if neither of these designators is
present, no history expansion occurs\&.
Input lines containing history expansions are echoed after being expanded,
but before any other expansions take place and before the command is
executed\&.  It is this expanded form that is recorded as the history event
for later references\&.
By default, a history reference with no event designator refers to the
same event as any preceding history reference on that command line; if it
is the only history reference in a command, it refers to the previous
However, if the option \fBCSH_JUNKIE_HISTORY\fP is set, then every history
reference with no event specification \fIalways\fP refers to the previous
For example, `\fB!\fP\&' is the event designator for the previous command, so
`\fB!!:1\fP\&' always refers to the first word of the previous command, and
`\fB!!$\fP\&' always refers to the last word of the previous command\&.  With
\fBCSH_JUNKIE_HISTORY\fP set, then `\fB!:1\fP\&' and `\fB!$\fP' function in the
same manner as `\fB!!:1\fP\&' and `\fB!!$\fP', respectively\&.  Conversely, if
\fBCSH_JUNKIE_HISTORY\fP is unset, then `\fB!:1\fP\&' and `\fB!$\fP' refer to the
first and last words, respectively, of the same event referenced by the
nearest other history reference preceding them on the current command
line, or to the previous command if there is no preceding reference\&.
The character sequence `\fB^\fP\fIfoo\fP\fB^\fP\fIbar\fP\&' (where `\fB^\fP' is
actually the second character of the \fBhistchars\fP parameter)
repeats the last command, replacing the string \fIfoo\fP with \fIbar\fP\&.
More precisely, the sequence `\fB^\fP\fIfoo\fP\fB^\fP\fIbar\fP\fB^\fP\&' is
synonymous with `\fB!!:s\fP\fB^\fP\fIfoo\fP\fB^\fP\fIbar\fP\fB^\fP\&', hence other
modifiers (see the section `Modifiers\&') may follow the final `\fB^\fP'\&.
In particular, `\fB^\fP\fIfoo\fP\fB^\fP\fIbar\fP\fB^:G\fP\&' performs a global
If the shell encounters the character sequence `\fB!"\fP\&'
in the input, the history mechanism is temporarily disabled until
the current list (see
\fIzshmisc\fP(1)) is fully parsed\&.  The `\fB!"\fP\&' is removed from the input, and any
subsequent `\fB!\fP\&' characters have no special significance\&.
A less convenient but more comprehensible form of command history support
is provided by the \fBfc\fP builtin\&.
.SS "Event Designators"
An event designator is a reference to a command\-line entry in the history
list\&.  In the list below, remember that the initial \fB`!\&'\fP in each item
may be changed to another character by setting the \fBhistchars\fP
.PD 0
Start a history expansion, except when followed by a blank, newline,
`\fB=\fP\&' or `\fB(\fP'\&.  If followed immediately by a word designator
(see the section `Word Designators\&'), this forms a history reference
with no event designator (see the section `Overview\&')\&.
Refer to the previous command\&.
By itself, this expansion
repeats the previous command\&.
Refer to command\-line \fIn\fP\&.
Refer to the current command\-line minus \fIn\fP\&.
Refer to the most recent command starting with \fIstr\fP\&.
Refer to the most recent command containing \fIstr\fP\&.  The trailing
`\fB?\fP\&' is necessary if this reference is to be followed by a modifier or
followed by any text that is not to be considered part of \fIstr\fP\&.
Refer to the current command line typed in so far\&.  The line is
treated as if it were complete up to and including the word before the
one with the `\fB!#\fP\&' reference\&.
Insulate a history reference from adjacent characters (if necessary)\&.
.SS "Word Designators"
A word designator indicates which word or words of a given command line are
to be included in a history reference\&.  A `\fB:\fP\&' usually
separates the event specification from the word designator\&.
It may be omitted only if the word designator begins with a
`\fB^\fP\&', `\fB$\fP', `\fB*\fP', `\fB\-\fP' or `\fB%\fP'\&.
Word designators include:
.PD 0
The first input word (command)\&.
The \fIn\fPth argument\&.
The first argument\&.  That is, \fB1\fP\&.
The last argument\&.
The word matched by (the most recent) \fB?\fP\fIstr\fP search\&.
A range of words; \fIx\fP defaults to \fB0\fP\&.
All the arguments, or a null value if there are none\&.
Abbreviates `\fIx\fP\fB\-$\fP\&'\&.
Like `\fIx\fP\fB*\fP\&' but omitting word \fB$\fP\&.
Note that a `\fB%\fP\&' word designator works only when used in one of
`\fB!%\fP\&', `\fB!:%\fP' or `\fB!?\fP\fIstr\fP\fB?:%\fP', and only when used after a
\fB!?\fP expansion (possibly in an earlier command)\&.  Anything else results
in an error, although the error may not be the most obvious one\&.
.SS "Modifiers"
After the optional word designator, you can add
a sequence of one or more of the following modifiers,
each preceded by a `\fB:\fP\&'\&.  These modifiers also work on the result
of \fIfilename generation\fP and \fIparameter expansion\fP, except where
.PD 0
Turn a file name into an absolute path:  prepends the current directory,
if necessary, and resolves any use of `\fB\&.\&.\fP\&' and `\fB\&.\fP' in the path\&.
Note that the transformation takes place even if the file or any
intervening directories do not exist\&.
As `\fBa\fP\&', but also resolve use of symbolic links where possible\&.
Note that resolution of `\fB\&.\&.\fP\&' occurs \fIbefore\fP resolution of symbolic
links\&.  This call is equivalent to \fBa\fP unless your system has the
\fBrealpath\fP system call (modern systems do)\&.
Resolve a command name into an absolute path by searching the command
path given by the \fBPATH\fP variable\&.  This does not work for commands
containing directory parts\&.  Note also that this does not usually work as
a glob qualifier unless a file of the same name is found in the
current directory\&.
Remove all but the extension\&.
Remove a trailing pathname component, leaving the head\&.  This works
like `\fBdirname\fP\&'\&.
Convert the words to all lowercase\&.
Print the new command but do not execute it\&.  Only works with history
Quote the substituted words, escaping further substitutions\&.  Works
with history expansion and parameter expansion, though for parameters
it is only useful if the resulting text is to be re\-evaluated such as
by \fBeval\fP\&.
Remove one level of quotes from the substituted words\&.
Remove a filename extension of the form `\fB\&.\fP\fIxxx\fP\&', leaving
the root name\&.
Substitute \fIr\fP for \fIl\fP as described below\&.
The substitution is done only for the
first string that matches \fIl\fP\&.  For arrays and for filename
generation, this applies to each word of the expanded text\&.  See
below for further notes on substitutions\&.
The forms `\fBgs/\fP\fIl\fP\fB/\fP\fIr\fP\&' and `\fBs/\fP\fIl\fP\fB/\fP\fIr\fP\fB/:G\fP'
perform global substitution, i\&.e\&. substitute every occurrence of \fIr\fP
for \fIl\fP\&.  Note that the \fBg\fP or \fB:G\fP must appear in exactly the
position shown\&.
See further notes on this form of substitution below\&.
Repeat the previous \fBs\fP substitution\&.  Like \fBs\fP, may be preceded
immediately by a \fBg\fP\&.  In parameter expansion the \fB&\fP must appear
inside braces, and in filename generation it must be quoted with a
Remove all leading pathname components, leaving the tail\&.  This works
like `\fBbasename\fP\&'\&.
Convert the words to all uppercase\&.
Like \fBq\fP, but break into words at whitespace\&.  Does not work with
parameter expansion\&.
The \fBs/\fP\fIl\fP\fB/\fP\fIr\fP\fB/\fP substitution works as follows\&.  By
default the left\-hand side of substitutions are not patterns, but
character strings\&.  Any character can be used as the delimiter in place
of `\fB/\fP\&'\&.  A backslash quotes the delimiter character\&.  The character
`\fB&\fP\&', in the right\-hand\-side \fIr\fP, is replaced by the text from the
left\-hand\-side \fIl\fP\&.  The `\fB&\fP\&' can be quoted with a backslash\&.  A
null \fIl\fP uses the previous string either from the previous \fIl\fP or
from the contextual scan string \fIs\fP from `\fB!?\fP\fIs\fP\&'\&.  You can
omit the rightmost delimiter if a newline immediately follows \fIr\fP;
the rightmost `\fB?\fP\&' in a context scan can similarly be omitted\&.  Note
the same record of the last \fIl\fP and \fIr\fP is maintained across all
forms of expansion\&.
Note that if a `\fB&\fP\&' is used within glob qualifers an extra backslash
is needed as a \fB&\fP is a special character in this case\&.
If the option \fBHIST_SUBST_PATTERN\fP is set, \fIl\fP is treated as
a pattern of the usual form described in
the section FILENAME GENERATION below\&.  This can be used in
all the places where modifiers are available; note, however, that
in globbing qualifiers parameter substitution has already taken place,
so parameters in the replacement string should be quoted to ensure
they are replaced at the correct time\&.
Note also that complicated patterns used in globbing qualifiers may
need the extended glob qualifier notation
\fB(#q:s/\fP\fI\&.\&.\&.\fP\fB/\fP\fI\&.\&.\&.\fP\fB/)\fP in order for the
shell to recognize the expression as a glob qualifier\&.  Further,
note that bad patterns in the substitution are not subject to
the \fBNO_BAD_PATTERN\fP option so will cause an error\&.
When \fBHIST_SUBST_PATTERN\fP is set, \fIl\fP may start with a \fB#\fP
to indicate that the pattern must match at the start of the string
to be substituted, and a \fB%\fP may appear at the start or after an \fB#\fP
to indicate that the pattern must match at the end of the string
to be substituted\&.  The \fB%\fP or \fB#\fP may be quoted with two
For example, the following piece of filename generation code
with the \fBEXTENDED_GLOB\fP option:
\fBprint *\&.c(#q:s/#%(#b)s(*)\&.c/\&'S${match[1]}\&.C'/)\fP
takes the expansion of \fB*\&.c\fP and applies the glob qualifiers in the
\fB(#q\fP\fI\&.\&.\&.\fP\fB)\fP expression, which consists of a substitution
modifier anchored to the start and end of each word (\fB#%\fP)\&.  This
turns on backreferences (\fB(#b)\fP), so that the parenthesised
subexpression is available in the replacement string as \fB${match[1]}\fP\&.
The replacement string is quoted so that the parameter is not substituted
before the start of filename generation\&.
The following \fBf\fP, \fBF\fP, \fBw\fP and \fBW\fP modifiers work only with
parameter expansion and filename generation\&.  They are listed here to
provide a single point of reference for all modifiers\&.
.PD 0
Repeats the immediately (without a colon) following modifier until the
resulting word doesn\&'t change any more\&.
Like \fBf\fP, but repeats only \fIn\fP times if the expression
\fIexpr\fP evaluates to \fIn\fP\&.  Any character can be used instead of
the `\fB:\fP\&'; if `\fB(\fP', `\fB[\fP', or `\fB{\fP'
is used as the opening delimiter,
the closing delimiter should be \&'\fB)\fP', `\fB]\fP', or `\fB}\fP',
Makes the immediately following modifier work on each word in the
Like \fBw\fP but words are considered to be the parts of the string
that are separated by \fIsep\fP\&. Any character can be used instead of
the `\fB:\fP\&'; opening parentheses are handled specially, see above\&.
Each part of a command argument that takes the form
`\fB>(\fP\fIlist\fP\fB)\fP\&' or
is subject to process substitution\&.  The expression may be preceeded
or followed by other strings except that, to prevent clashes with
commonly occurring strings and patterns, the last
form must occur at the start of a command argument, and the forms
are only expanded when first parsing command or assignment arguments\&.
Process substitutions may be used following redirection operators; in this
case, the substitution must appear with no trailing string\&.
In the case of the \fB<\fP or \fB>\fP forms, the shell runs the commands in
\fIlist\fP as a subprocess of the job executing the shell command line\&.
If the system supports the \fB/dev/fd\fP
mechanism, the command argument is the name of the device file
corresponding to a file descriptor; otherwise, if the system supports named
pipes (FIFOs), the command argument will be a named pipe\&.  If the form with
\fB>\fP is selected then writing on this special file will provide input for
\fIlist\fP\&.  If \fB<\fP is used, then the file passed as an argument will
be connected to the output of the \fIlist\fP process\&.  For example,
\fB\fBpaste <(cut \-f1\fP \fIfile1\fP\fB) <(cut \-f3\fP \fIfile2\fP\fB) |
tee >(\fP\fIprocess1\fP\fB) >(\fP\fIprocess2\fP\fB) >/dev/null\fP\fP
cuts fields 1 and 3 from the files \fIfile1\fP and \fIfile2\fP respectively,
pastes the results together, and sends it to the processes
\fIprocess1\fP and \fIprocess2\fP\&.
If \fB=(\fP\fI\&.\&.\&.\fP\fB)\fP is used instead of
then the file passed as an argument will be the name
of a temporary file containing the output of the \fIlist\fP
process\&.  This may be used instead of the \fB<\fP
form for a program that expects to lseek (see \fIlseek\fP(2))
on the input file\&.
There is an optimisation for substitutions of the form
\fB=(<<<\fP\fIarg\fP\fB)\fP, where \fIarg\fP is a single\-word argument
to the here\-string redirection \fB<<<\fP\&.  This form produces a file name
containing the value of \fIarg\fP after any substitutions have been
performed\&.  This is handled entirely within the current shell\&.  This is
effectively the reverse of the special form \fB$(<\fP\fIarg\fP\fB)\fP
which treats \fIarg\fP as a file name and replaces it with the file\&'s
The \fB=\fP form is useful as both the \fB/dev/fd\fP and the named pipe
implementation of \fB<(\fP\fI\&.\&.\&.\fP\fB)\fP have drawbacks\&.  In 
the former case, some programmes may automatically close the file
descriptor in question before examining the file on the command line,
particularly if this is necessary for security reasons such as when the
programme is running setuid\&.  In the second case, if the
programme does not actually open the file, the subshell attempting to read
from or write to the pipe will (in a typical implementation, different
operating systems may have different behaviour) block for ever and have to
be killed explicitly\&.  In both cases, the shell actually supplies the
information using a pipe, so that programmes that expect to lseek
(see \fIlseek\fP(2)) on the file will not work\&.
Also note that the previous example can be more compactly and
efficiently written (provided the \fBMULTIOS\fP option is set) as:
\fB\fBpaste <(cut \-f1\fP \fIfile1\fP\fB) <(cut \-f3\fP \fIfile2\fP\fB)\fP \e 
\fB> >(\fP\fIprocess1\fP\fB) > >(\fP\fIprocess2\fP\fB)\fP\fP
The shell uses pipes instead of FIFOs to implement the latter
two process substitutions in the above example\&.
There is an additional problem with \fB>(\fP\fIprocess\fP\fB)\fP; when
this is attached to an external command, the parent shell does not wait
for \fIprocess\fP to finish and hence an immediately following command
cannot rely on the results being complete\&.  The problem and solution are
the same as described in the section \fIMULTIOS\fP in
\fIzshmisc\fP(1)\&.  Hence in a simplified
version of the example above:
\fB\fBpaste <(cut \-f1\fP \fIfile1\fP\fB) <(cut \-f3\fP \fIfile2\fP\fB)\fP \fB> >(\fP\fIprocess\fP\fB)\fP\fP
(note that no \fBMULTIOS\fP are involved), \fIprocess\fP will be run
asynchronously as far as the parent shell is concerned\&.  The workaround is:
\fB\fB{ paste <(cut \-f1\fP \fIfile1\fP\fB) <(cut \-f3\fP \fIfile2\fP\fB) }\fP \fB> >(\fP\fIprocess\fP\fB)\fP\fP
The extra processes here are
spawned from the parent shell which will wait for their completion\&.
The character `\fB$\fP\&' is used to introduce parameter expansions\&.
for a description of parameters, including arrays, associative arrays,
and subscript notation to access individual array elements\&.
Note in particular the fact that words of unquoted parameters are not
automatically split on whitespace unless the option \fBSH_WORD_SPLIT\fP is
set; see references to this option below for more details\&.  This is an
important difference from other shells\&.
In the expansions discussed below that require a pattern, the form of
the pattern is the same as that used for filename generation;
see the section `Filename Generation\&'\&.  Note that these patterns, along with
the replacement text of any substitutions, are themselves subject to
parameter expansion, command substitution, and arithmetic expansion\&.
In addition to the following operations, the colon modifiers described in
the section `Modifiers\&' in the section `History Expansion' can be
applied:  for example, \fB${i:s/foo/bar/}\fP performs string
substitution on the expansion of parameter \fB$i\fP\&.
.PD 0
The value, if any, of the parameter \fIname\fP is substituted\&.
The braces are required if the expansion is to be followed by
a letter, digit, or underscore that is not to be interpreted
as part of \fIname\fP\&.  In addition, more complicated forms of substitution
usually require the braces to be present; exceptions, which only apply if
the option \fBKSH_ARRAYS\fP is not set, are a single subscript or any colon
modifiers appearing after the name, or any of the characters `\fB^\fP\&',
`\fB=\fP\&', `\fB~\fP', `\fB#\fP' or `\fB+\fP' appearing before the name, all of
which work with or without braces\&.
If \fIname\fP is an array parameter, and the \fBKSH_ARRAYS\fP option is not
set, then the value of each
element of \fIname\fP is substituted, one element per word\&.  Otherwise, the
expansion results in one word only; with \fBKSH_ARRAYS\fP, this is the first
element of an array\&.  No field splitting is done on the result unless the
\fBSH_WORD_SPLIT\fP option is set\&.
See also the flags \fB=\fP and \fBs:\fP\fIstring\fP\fB:\fP\&.
If \fIname\fP is the name of a set parameter `\fB1\fP\&' is substituted,
otherwise `\fB0\fP\&' is substituted\&.
.PD 0
If \fIname\fP is set, or in the second form is non\-null, then substitute
its value; otherwise substitute \fIword\fP\&.  In the second form \fIname\fP
may be omitted, in which case \fIword\fP is always substituted\&.
.PD 0
If \fIname\fP is set, or in the second form is non\-null, then substitute
\fIword\fP; otherwise substitute nothing\&.
.PD 0
.PD 0
In the first form, if \fIname\fP is unset then set it to \fIword\fP; in the
second form, if \fIname\fP is unset or null then set it to \fIword\fP; and
in the third form, unconditionally set \fIname\fP to \fIword\fP\&.  In all
forms, the value of the parameter is then substituted\&.
.PD 0
In the first form, if \fIname\fP is set, or in the second form if \fIname\fP
is both set and non\-null, then substitute its value; otherwise, print
\fIword\fP and exit from the shell\&.  Interactive shells instead return to
the prompt\&.  If \fIword\fP is omitted, then a standard message is printed\&.
In any of the above expressions that test a variable and substitute an
alternate \fIword\fP, note that you can use standard shell quoting in the
\fIword\fP value to selectively override the splitting done by the
\fBSH_WORD_SPLIT\fP option and the \fB=\fP flag, but not splitting by the
\fBs:\fP\fIstring\fP\fB:\fP flag\&.
In the following expressions, when \fIname\fP is an array and
the substitution is not quoted, or if the `\fB(@)\fP\&' flag or the
\fIname\fP\fB[@]\fP syntax is used, matching and replacement is
performed on each array element separately\&.
.PD 0
.PD 0
If the \fIpattern\fP matches the beginning of the value of
\fIname\fP, then substitute the value of \fIname\fP with
the matched portion deleted; otherwise, just
substitute the value of \fIname\fP\&.  In the first
form, the smallest matching pattern is preferred;
in the second form, the largest matching pattern is
.PD 0
If the \fIpattern\fP matches the end of the value of
\fIname\fP, then substitute the value of \fIname\fP with
the matched portion deleted; otherwise, just
substitute the value of \fIname\fP\&.  In the first
form, the smallest matching pattern is preferred;
in the second form, the largest matching pattern is
If the \fIpattern\fP matches the value of \fIname\fP, then substitute
the empty string; otherwise, just substitute the value of \fIname\fP\&.
If \fIname\fP is an array
the matching array elements are removed (use the `\fB(M)\fP\&' flag to
remove the non\-matched elements)\&.
.PD 0
This syntax gives effects similar to parameter subscripting
in the form \fB$\fP\fIname\fP\fB{\fP\fIstart\fP\fB,\fP\fIend\fP\fB}\fP, but is
compatible with other shells; note that both \fIoffset\fP and \fIlength\fP
are interpreted differently from the components of a subscript\&.
If \fIoffset\fP is non\-negative, then if the variable \fIname\fP is a
scalar substitute the contents starting \fIoffset\fP characters from the
first character of the string, and if \fIname\fP is an array substitute
elements starting \fIoffset\fP elements from the first element\&.  If
\fIlength\fP is given, substitute that many characters or elements,
otherwise the entire rest of the scalar or array\&.
A positive \fIoffset\fP is always treated as the offset of a character or
element in \fIname\fP from the first character or element of the array
(this is different from native zsh subscript notation)\&.  Hence 0
refers to the first character or element regardless of the setting of
the option \fBKSH_ARRAYS\fP\&.
A negative offset counts backwards from the end of the scalar or array,
so that \-1 corresponds to the last character or element, and so on\&.
\fIlength\fP is always treated directly as a length and hence may not be
negative\&.  The option \fBMULTIBYTE\fP is obeyed, i\&.e\&. the offset and length
count multibyte characters where appropriate\&.
\fIoffset\fP and \fIlength\fP undergo the same set of shell substitutions
as for scalar assignment; in addition, they are then subject to arithmetic
evaluation\&.  Hence, for example
\fBprint ${foo:3}
print ${foo: 1 + 2}
print ${foo:$(( 1 + 2))}
print ${foo:$(echo 1 + 2)}\fP
all have the same effect, extracting the string starting at the fourth
character of \fB$foo\fP if the substution would otherwise return a scalar,
or the array starting at the fourth element if \fB$foo\fP would return an
array\&.  Note that with the option \fBKSH_ARRAYS\fP \fB$foo\fP always returns
a scalar (regardless of the use of the offset syntax) and a form
such as \fB$foo[*]:3\fP is required to extract elements of an array named
If \fIoffset\fP is negative, the \fB\-\fP may not appear immediately
after the \fB:\fP as this indicates the
\fB${\fP\fIname\fP\fB:\-\fP\fIword\fP\fB}\fP form of substitution\&.  Instead, a space
may be inserted before the \fB\-\fP\&.  Furthermore, neither \fIoffset\fP nor
\fIlength\fP may begin with an alphabetic character or \fB&\fP as these are
used to indicate history\-style modifiers\&.  To substitute a value from a
variable, the recommended approach is to proceed it with a \fB$\fP as this
signifies the intention (parameter substitution can easily be rendered
unreadable); however, as arithmetic substitution is performed, the
expression \fB${var: offs}\fP does work, retrieving the offset from
For further compatibility with other shells there is a special case
for array offset 0\&.  This usually accesses to the
first element of the array\&.  However, if the substitution refers the
positional parameter array, e\&.g\&. \fB$@\fP or \fB$*\fP, then offset 0
instead refers to \fB$0\fP, offset 1 refers to \fB$1\fP, and so on\&.  In
other words, the positional parameter array is effectively extended by
prepending \fB$0\fP\&.  Hence \fB${*:0:1}\fP substitutes \fB$0\fP and
\fB${*:1:1}\fP substitutes \fB$1\fP\&.
.PD 0
Replace the longest possible match of \fIpattern\fP in the expansion of
parameter \fIname\fP by string \fIrepl\fP\&.  The first form
replaces just the first occurrence, the second form all occurrences\&.
Both \fIpattern\fP and \fIrepl\fP are subject to double\-quoted substitution,
so that expressions like \fB${name/$opat/$npat}\fP will work, but note the
usual rule that pattern characters in \fB$opat\fP are not treated specially
unless either the option \fBGLOB_SUBST\fP is set, or \fB$opat\fP is instead
substituted as \fB${~opat}\fP\&.
The \fIpattern\fP may begin with a `\fB#\fP\&', in which case the
\fIpattern\fP must match at the start of the string, or `\fB%\fP\&', in
which case it must match at the end of the string, or `\fB#%\fP\&' in which
case the \fIpattern\fP must match the entire string\&.  The \fIrepl\fP may
be an empty string, in which case the final `\fB/\fP\&' may also be omitted\&.
To quote the final `\fB/\fP\&' in other cases it should be preceded by a
single backslash; this is not necessary if the
`\fB/\fP\&' occurs inside a substituted parameter\&.  Note also that the `\fB#\fP',
`\fB%\fP\&' and `\fB#%\fP are not active if they occur inside a substituted
parameter, even at the start\&.
The first `\fB/\fP\&' may be preceded by a `\fB:\fP', in which case the match
will only succeed if it matches the entire word\&.  Note also the
effect of the \fBI\fP and \fBS\fP parameter expansion flags below; however,
the flags \fBM\fP, \fBR\fP, \fBB\fP, \fBE\fP and \fBN\fP are not useful\&.
For example,
\fBfoo="twinkle twinkle little star" sub="t*e" rep="spy"
print ${foo//${~sub}/$rep}
print ${(S)foo//${~sub}/$rep}\fP
Here, the `\fB~\fP\&' ensures that the text of \fB$sub\fP is treated as a
pattern rather than a plain string\&.  In the first case, the longest
match for \fBt*e\fP is substituted and the result is `\fBspy star\fP\&',
while in the second case, the shortest matches are taken and the
result is `\fBspy spy lispy star\fP\&'\&.
If \fIspec\fP is one of the above substitutions, substitute
the length in characters of the result instead of
the result itself\&.  If \fIspec\fP is an array expression,
substitute the number of elements of the result\&.
Note that `\fB^\fP\&', `\fB=\fP', and `\fB~\fP', below, must appear
to the left of `\fB#\fP\&' when these forms are combined\&.
Turn on the \fBRC_EXPAND_PARAM\fP option for the
evaluation of \fIspec\fP; if the `\fB^\fP\&' is doubled, turn it off\&.
When this option is set, array expansions of the form
where the parameter \fIxx\fP
is set to \fB(\fP\fIa b c\fP\fB)\fP, are substituted with
`\fIfooabar foobbar foocbar\fP\&' instead of the default
`\fIfooa b cbar\fP\&'\&.  Note that an empty array will therefore cause
all arguments to be removed\&.
Internally, each such expansion is converted into the
equivalent list for brace expansion\&.  E\&.g\&., \fB${^var}\fP becomes
\fB{$var[1],$var[2],\fP\&.\&.\&.\fB}\fP, and is processed as described in
the section `Brace Expansion\&' below\&.
If word splitting is also in effect the
\fB$var[\fP\fIN\fP\fB]\fP may themselves be split into different list
Perform word splitting using the rules for \fBSH_WORD_SPLIT\fP during the
evaluation of \fIspec\fP, but regardless of whether the parameter appears in
double quotes; if the `\fB=\fP\&' is doubled, turn it off\&.
This forces parameter expansions to be split into
separate words before substitution, using \fBIFS\fP as a delimiter\&.
This is done by default in most other shells\&.
Note that splitting is applied to \fIword\fP in the assignment forms
of \fIspec\fP \fIbefore\fP the assignment to \fIname\fP is performed\&.
This affects the result of array assignments with the \fBA\fP flag\&.
Turn on the \fBGLOB_SUBST\fP option for the evaluation of
\fIspec\fP; if the `\fB~\fP\&' is doubled, turn it off\&.  When this option is
set, the string resulting from the expansion will be interpreted as a
pattern anywhere that is possible, such as in filename expansion and
filename generation and pattern\-matching contexts like the right
hand side of the `\fB=\fP\&' and `\fB!=\fP' operators in conditions\&.
In nested substitutions, note that the effect of the \fB~\fP applies to the
result of the current level of substitution\&.  A surrounding pattern
operation on the result may cancel it\&.  Hence, for example, if the
parameter \fBfoo\fP is set to \fB*\fP, \fB${~foo//\e*/*\&.c}\fP is substituted by
the pattern \fB*\&.c\fP, which may be expanded by filename generation, but
\fB${${~foo}//\e*/*\&.c}\fP substitutes to the string \fB*\&.c\fP, which will not
be further expanded\&.
If a \fB${\fP\&.\&.\&.\fB}\fP type parameter expression or a
\fB$(\fP\&.\&.\&.\fB)\fP type command substitution is used in place of
\fIname\fP above, it is expanded first and the result is used as if
it were the value of \fIname\fP\&.  Thus it is
possible to perform nested operations:  \fB${${foo#head}%tail}\fP
substitutes the value of \fB$foo\fP with both `\fBhead\fP\&' and `\fBtail\fP'
deleted\&.  The form with \fB$(\fP\&.\&.\&.\fB)\fP is often useful in
combination with the flags described next; see the examples below\&.
Each \fIname\fP or nested \fB${\fP\&.\&.\&.\fB}\fP in a parameter expansion may
also be followed by a subscript expression as described in
\fIArray Parameters\fP in \fIzshparam\fP(1)\&.
Note that double quotes may appear around nested expressions, in which
case only the part inside is treated as quoted; for example,
\fB${(f)"$(foo)"}\fP quotes the result of \fB$(foo)\fP, but the flag `\fB(f)\fP\&'
(see below) is applied using the rules for unquoted expansions\&.  Note
further that quotes are themselves nested in this context; for example, in
\fB"${(@f)"$(foo)"}"\fP, there are two sets of quotes, one surrounding the
whole expression, the other (redundant) surrounding the \fB$(foo)\fP as
.SS "Parameter Expansion Flags"
If the opening brace is directly followed by an opening parenthesis,
the string up to the matching closing parenthesis will be taken as a
list of flags\&.  In cases where repeating a flag is meaningful, the
repetitions need not be consecutive; for example, `(\fBq%q%q\fP)\&'
means the same thing as the more readable `(\fB%%qqq\fP)\&'\&.  The
following flags are supported:
.PD 0
Evaluate the resulting words as numeric expressions and output the
characters corresponding to the resulting integer\&.  Note that this form is
entirely distinct from use of the \fB#\fP without parentheses\&.
If the \fBMULTIBYTE\fP option is set and the number is greater than 127
(i\&.e\&. not an ASCII character) it is treated as a Unicode character\&.
Expand all \fB%\fP escapes in the resulting words in the same way as in
prompts (see 
EXPANSION OF PROMPT SEQUENCES in \fIzshmisc\fP(1))\&. If this flag is given twice,
full prompt expansion is done on the resulting words, depending on the
In double quotes, array elements are put into separate words\&.
E\&.g\&., `\fB"${(@)foo}"\fP\&' is equivalent to `\fB"${foo[@]}"\fP' and
`\fB"${(@)foo[1,2]}"\fP\&' is the same as `\fB"$foo[1]" "$foo[2]"\fP'\&.
This is distinct from \fIfield splitting\fP by the the \fBf\fP, \fBs\fP
or \fBz\fP flags, which still applies within each array element\&.
Create an array parameter with `\fB${\fP\&.\&.\&.\fB=\fP\&.\&.\&.\fB}\fP\&',
`\fB${\fP\&.\&.\&.\fB:=\fP\&.\&.\&.\fB}\fP\&' or `\fB${\fP\&.\&.\&.\fB::=\fP\&.\&.\&.\fB}\fP'\&.
If this flag is repeated (as in `\fBAA\fP\&'), create an associative
array parameter\&.  Assignment is made before sorting or padding\&.
The \fIname\fP part may be a subscripted range for ordinary
arrays; the \fIword\fP part \fImust\fP be converted to an array, for
example by using `\fB${(AA)=\fP\fIname\fP\fB=\fP\&.\&.\&.\fB}\fP\&' to activate
field splitting, when creating an associative array\&.
Sort in array index order; when combined with `\fBO\fP\&' sort in reverse
array index order\&.  Note that `\fBa\fP\&' is therefore equivalent to the
default but `\fBOa\fP\&' is useful for obtaining an array's elements in reverse
With \fB${#\fP\fIname\fP\fB}\fP, count the total number of characters in an array,
as if the elements were concatenated with spaces between them\&.
Capitalize the resulting words\&.  `Words\&' in this case refers to sequences
of alphanumeric characters separated by non\-alphanumerics, \fInot\fP to words
that result from field splitting\&.
Assume the string or array elements contain directories and attempt
to substitute the leading part of these by names\&.  The remainder of
the path (the whole of it if the leading part was not subsituted)
is then quoted so that the whole string can be used as a shell
argument\&.  This is the reverse of `\fB~\fP\&' substitution:  see
the section FILENAME EXPANSION below\&.
Perform \fIparameter expansion\fP, \fIcommand substitution\fP and
\fIarithmetic expansion\fP on the result\&. Such expansions can be
nested but too deep recursion may have unpredictable effects\&.
Split the result of the expansion at newlines\&. This is a shorthand
for `\fBps:\en:\fP\&'\&.
Join the words of arrays together using newline as a separator\&.
This is a shorthand for `\fBpj:\en:\fP\&'\&.
Sort case\-insensitively\&.  May be combined with `\fBn\fP\&' or `\fBO\fP'\&.
If \fIname\fP refers to an associative array, substitute the \fIkeys\fP
(element names) rather than the values of the elements\&.  Used with
subscripts (including ordinary arrays), force indices or keys to be
substituted even if the subscript form refers to values\&.  However,
this flag may not be combined with subscript ranges\&.
Convert all letters in the result to lower case\&.
Sort decimal integers numerically; if the first differing
characters of two test strings are not digits, sorting
is lexical\&.   Integers with more initial zeroes
are sorted before those with fewer or none\&.  Hence the array `\fBfoo1 foo02
foo2 foo3 foo20 foo23\fP\&' is sorted into the order shown\&.
May be combined with `\fBi\fP\&' or `\fBO\fP'\&.
Sort the resulting words in ascending order; if this appears on its
own the sorting is lexical and case\-sensitive (unless the locale
renders it case\-insensitive)\&.  Sorting in ascending order is the
default for other forms of sorting, so this is ignored if combined
with `\fBa\fP\&', `\fBi\fP' or `\fBn\fP'\&.
Sort the resulting words in descending order; `\fBO\fP\&' without `\fBa\fP',
`\fBi\fP\&' or `\fBn\fP' sorts in reverse lexical order\&.  May be combined
with `\fBa\fP\&', `\fBi\fP' or `\fBn\fP' to reverse the order of sorting\&.
This forces the value of the parameter \fIname\fP to be interpreted as a
further parameter name, whose value will be used where appropriate\&.
Note that flags set with one of the \fBtypeset\fP family of commands
(in particular case transformations) are not applied to the value of
\fIname\fP used in this fashion\&.
If used with a nested parameter or command substitution, the result of that
will be taken as a parameter name in the same way\&.  For example, if you
have `\fBfoo=bar\fP\&' and `\fBbar=baz\fP', the strings \fB${(P)foo}\fP,
\fB${(P)${foo}}\fP, and \fB${(P)$(echo bar)}\fP will be expanded to `\fBbaz\fP\&'\&.
Quote characters that are special to the shell in the resulting words with
backslashes; unprintable or invalid characters are quoted using the
\fB$\&'\e\fP\fINNN\fP\fB'\fP form, with separate quotes for each octet\&.
If this flag is given twice, the resulting words are quoted in single
quotes and if it is given three times, the words are quoted in double
quotes; in these forms no special handling of unprintable or invalid
characters is attempted\&.  If the flag is given four times, the words are
quoted in single quotes preceded by a \fB$\fP\&.  Note that in all three of
these forms quoting is done unconditionally, even if this does not change
the way the resulting string would be interpreted by the shell\&.
If a \fBq\-\fP is given (only a single \fBq\fP may appear), a minimal
form of single quoting is used that only quotes the string if needed to
protect special characters\&.  Typically this form gives the most readable
Remove one level of quotes from the resulting words\&.
Use a string describing the type of the parameter where the value
of the parameter would usually appear\&. This string consists of keywords
separated by hyphens (`\fB\-\fP\&')\&. The first keyword in the string describes
the main type, it can be one of `\fBscalar\fP\&', `\fBarray\fP', `\fBinteger\fP',
`\fBfloat\fP\&' or `\fBassociation\fP'\&. The other keywords describe the type in
more detail:
.PD 0
for local parameters
for left justified parameters
for right justified parameters with leading blanks
for right justified parameters with leading zeros
for parameters whose value is converted to all lower case when it is
for parameters whose value is converted to all upper case when it is
for readonly parameters
for tagged parameters
for exported parameters
for arrays which keep only the first occurrence of duplicated values
for parameters with the `hide\&' flag
for special parameters defined by the shell
Expand only the first occurrence of each unique word\&.
Convert all letters in the result to upper case\&.
Used with \fBk\fP, substitute (as two consecutive words) both the key
and the value of each associative array element\&.  Used with subscripts,
force values to be substituted even if the subscript form refers to
indices or keys\&.
Make any special characters in the resulting words visible\&.
With \fB${#\fP\fIname\fP\fB}\fP, count words in arrays or strings; the \fBs\fP
flag may be used to set a word delimiter\&.
Similar to \fBw\fP with the difference that empty words between
repeated delimiters are also counted\&.
With this flag, parsing errors occurring with the \fBQ\fP, \fBe\fP and \fB#\fP
flags or the pattern matching forms such as
`\fB${\fP\fIname\fP\fB#\fP\fIpattern\fP\fB}\fP\&' are reported\&.  Without the flag,
errors are silently ignored\&.
Split the result of the expansion into words using shell parsing to
find the words, i\&.e\&. taking into account any quoting in the value\&.
Comments are not treated specially but as ordinary strings, similar
to interactive shells with the \fBINTERACTIVE_COMMENTS\fP option unset\&.
Note that this is done very late, as for the `\fB(s)\fP\&' flag\&. So to
access single words in the result, one has to use nested expansions as 
in `\fB${${(z)foo}[2]}\fP\&'\&. Likewise, to remove the quotes in the
resulting words one would do: `\fB${(Q)${(z)foo}}\fP\&'\&.
Split the result of the expansion on null bytes\&.  This is a shorthand
for `\fBps:\e0:\fP\&'\&.
The following flags (except \fBp\fP) are followed by one or more arguments
as shown\&.  Any character, or the matching pairs `\fB(\fP\&.\&.\&.\fB)\fP\&',
`\fB{\fP\&.\&.\&.\fB}\fP\&', `\fB[\fP\&.\&.\&.\fB]\fP', or `\fB<\fP\&.\&.\&.\fB>\fP', may be used in place
of a colon as delimiters, but note that when a flag takes more than one
argument, a matched pair of delimiters must surround each argument\&.
.PD 0
Recognize the same escape sequences as the \fBprint\fP builtin
in string arguments to any of the flags described below that
follow this argument\&.
Force string arguments to any of the flags below that follow within
the parentheses to be treated as patterns\&.  Compare with a \fB~\fP
outside parentheses, which forces the entire substituted string to
be treated as a pattern\&.  Hence, for example,
\fB[[ "?" = ${(~j\&.|\&.)array} ]]\fP
with the \fBEXTENDED_GLOB\fP option set succeeds if and only if \fB$array\fP
contains the string `\fB?\fP\&' as an element\&.  The argument may be
repeated to toggle the behaviour; its effect only lasts to the
end of the parenthesised group\&.
Join the words of arrays together using \fIstring\fP as a separator\&.
Note that this occurs before field splitting by the \fBs:\fP\fIstring\fP\fB:\fP
flag or the \fBSH_WORD_SPLIT\fP option\&.
Pad the resulting words on the left\&.  Each word will be truncated if
required and placed in a field \fIexpr\fP characters wide\&.
The arguments \fB:\fP\fIstring1\fP\fB:\fP and \fB:\fP\fIstring2\fP\fB:\fP are
optional; neither, the first, or both may be given\&.  Note that the same
pairs of delimiters must be used for each of the three arguments\&.  The
space to the left will be filled with \fIstring1\fP (concatenated as
often as needed) or spaces if \fIstring1\fP is not given\&.  If both
\fIstring1\fP and \fIstring2\fP are given, \fBstring2\fP is inserted once
directly to the left of each word, truncated if necessary, before
\fIstring1\fP is used to produce any remaining padding\&.
If the \fBMULTIBYTE\fP option is in effect, the flag \fBm\fP may also
be given, in which case widths will be used for the calculation of
padding; otherwise individual multibyte characters are treated as occupying
one unit of width\&.
If the \fBMULTIBYTE\fP option is not in effect, each byte in the string is
treated as occupying one unit of width\&.
Control characters are always assumed to be one unit wide; this allows the
mechanism to be used for generating repetitions of control characters\&.
Only useful together with one of the flags \fBl\fP or \fBr\fP or with the
\fB#\fP length operator when the \fBMULTIBYTE\fP option
is in effect\&.  Use the character width reported by the system in
calculating how much of the string it occupies or the overall
length of the string\&.  Most printable characters have a width of one
unit, however certain Asian character sets and certain special effects
use wider characters; combining characters have zero width\&.
Non\-printable characters are arbitrarily counted as zero width; how they
would actually be displayed will vary\&.
If the \fBm\fP is repeated, the character either counts zero (if it has
zero width), else one\&.  For printable character strings this has the
effect of counting the number of glyphs (visibly separate characters),
except for the case where combining characters themselves have non\-zero
width (true in certain alphabets)\&.
As \fBl\fP, but pad the words on the right and insert \fIstring2\fP
immediately to the right of the string to be padded\&.
Left and right padding may be used together\&.  In this case the strategy
is to apply left padding to the first half width of each of the resulting
words, and right padding to the second half\&.  If the string to be
padded has odd width the extra padding is applied on the left\&.
Force field splitting at the
separator \fIstring\fP\&.  Note that a \fIstring\fP of two or more
characters means that all of them must match in sequence; this differs from
the treatment of two or more characters in the \fBIFS\fP parameter\&.
See also the \fB=\fP flag and the \fBSH_WORD_SPLIT\fP option\&.
For historical reasons, the usual behaviour that empty array elements
are retained inside double quotes is disabled for arrays generated
by splitting; hence the following:
print \-l "${(s\&.:\&.)line}"\fP
produces two lines of output for \fBone\fP and \fBthree\fP and elides the
empty field\&.  To override this behaviour, supply the "(@)" flag as well,
i\&.e\&.  \fB"${(@s\&.:\&.)line}"\fP\&.
As \fBz\fP but takes a combination of option letters between a following
pair of delimiter characters\&.  \fB(Z+c+)\fP
causes comments to be parsed as a string and retained; any field in the
resulting array beginning with an unquoted comment character is a
comment\&.  \fB(Z+C+)\fP causes comments to be parsed
and removed\&.  The rule for comments is standard: anything between a word
starting with the third character of \fB$HISTCHARS\fP, default \fB#\fP, up to
the next newline is a comment\&.  \fB(Z+n+)\fP causes
unquoted newlines to be treated as ordinary whitespace, else they are
treated as if they are shell code delimiters and converted to
The underscore (\fB_\fP) flag is reserved for future use\&.  As of this
revision of zsh, there are no valid \fIflags\fP; anything following an
underscore, other than an empty pair of delimiters, is treated as an
error, and the flag itself has no effect\&.
The following flags are meaningful with the \fB${\fP\&.\&.\&.\fB#\fP\&.\&.\&.\fB}\fP or
\fB${\fP\&.\&.\&.\fB%\fP\&.\&.\&.\fB}\fP forms\&.  The \fBS\fP and \fBI\fP flags may also be
used with the \fB${\fP\&.\&.\&.\fB/\fP\&.\&.\&.\fB}\fP forms\&.
.PD 0
Search substrings as well as beginnings or ends; with \fB#\fP start
from the beginning and with \fB%\fP start from the end of the string\&.
With substitution via \fB${\fP\&.\&.\&.\fB/\fP\&.\&.\&.\fB}\fP or
\fB${\fP\&.\&.\&.\fB//\fP\&.\&.\&.\fB}\fP, specifies non\-greedy matching, i\&.e\&. that the
shortest instead of the longest match should be replaced\&.
Search the \fIexpr\fPth match (where \fIexpr\fP evaluates to a number)\&.
This only applies when searching for substrings, either with the \fBS\fP
flag, or with \fB${\fP\&.\&.\&.\fB/\fP\&.\&.\&.\fB}\fP (only the \fIexpr\fPth match is
substituted) or \fB${\fP\&.\&.\&.\fB//\fP\&.\&.\&.\fB}\fP (all matches from the
\fIexpr\fPth on are substituted)\&.  The default is to take the first match\&.
The \fIexpr\fPth match is counted such that there is either one or zero
matches from each starting position in the string, although for global
substitution matches overlapping previous replacements are ignored\&.  With
the \fB${\fP\&.\&.\&.\fB%\fP\&.\&.\&.\fB}\fP and \fB${\fP\&.\&.\&.\fB%%\fP\&.\&.\&.\fB}\fP forms, the starting
position for the match moves backwards from the end as the index increases,
while with the other forms it moves forward from the start\&.
Hence with the string
\fBwhich switch is the right switch for Ipswich?\fP
substitutions of the form
\fB${\fP(\fBSI:\fP\fIN\fP\fB:\fP)\fBstring#w*ch}\fP as \fIN\fP increases
from 1 will match and remove `\fBwhich\fP\&', `\fBwitch\fP', `\fBwitch\fP' and
`\fBwich\fP\&'; the form using `\fB##\fP' will match and remove `\fBwhich switch
is the right switch for Ipswich\fP\&', `\fBwitch is the right switch for
Ipswich\fP\&', `\fBwitch for Ipswich\fP' and `\fBwich\fP'\&. The form using `\fB%\fP'
will remove the same matches as for `\fB#\fP\&', but in reverse order, and the
form using `\fB%%\fP\&' will remove the same matches as for `\fB##\fP' in reverse
Include the index of the beginning of the match in the result\&.
Include the index of the end of the match in the result\&.
Include the matched portion in the result\&.
Include the length of the match in the result\&.
Include the unmatched portion in the result (the \fIR\fPest)\&.
.SS "Rules"
Here is a summary of the rules for substitution; this assumes that braces
are present around the substitution, i\&.e\&. \fB${\&.\&.\&.}\fP\&.  Some particular
examples are given below\&.  Note that the Zsh Development Group accepts
\fIno responsibility\fP for any brain damage which may occur during the
reading of the following rules\&.
.PD 0
\fB1\&.\fP \fINested Substitution\fP
If multiple nested \fB${\&.\&.\&.}\fP forms are present, substitution is
performed from the inside outwards\&.  At each level, the substitution takes
account of whether the current value is a scalar or an array, whether the
whole substitution is in double quotes, and what flags are supplied to the
current level of substitution, just as if the nested substitution were the
outermost\&.  The flags are not propagated up to enclosing
substitutions; the nested substitution will return either a scalar or an
array as determined by the flags, possibly adjusted for quoting\&.  All the
following steps take place where applicable at all levels of substitution\&.
Note that, unless the `\fB(P)\fP\&' flag is present, the flags and any subscripts
apply directly to the value of the nested substitution; for example, the
expansion \fB${${foo}}\fP behaves exactly the same as \fB${foo}\fP\&.
At each nested level of substitution, the substituted words undergo all
forms of single\-word substitution (i\&.e\&. not filename generation), including
command substitution, arithmetic expansion and filename expansion
(i\&.e\&. leading \fB~\fP and \fB=\fP)\&.  Thus, for example, \fB${${:\-=cat}:h}\fP
expands to the directory where the \fBcat\fP program resides\&.  (Explanation:
the internal substitution has no parameter but a default value \fB=cat\fP,
which is expanded by filename expansion to a full path; the outer
substitution then applies the modifier \fB:h\fP and takes the directory part
of the path\&.)
\fB2\&.\fP \fIInternal Parameter Flags\fP
Any parameter flags set by one of the \fBtypeset\fP family of commands,
in particular the \fBL\fP, \fBR\fP, \fBZ\fP, \fBu\fP and \fBl\fP flags for padding
and capitalization, are applied directly to the parameter value\&.
\fB3\&.\fP \fIParameter Subscripting\fP
If the value is a raw parameter reference with a subscript, such as
\fB${\fP\fIvar\fP\fB[3]}\fP, the effect of subscripting is applied directly to
the parameter\&.  Subscripts are evaluated left to right; subsequent
subscripts apply to the scalar or array value yielded by the previous
subscript\&.  Thus if \fBvar\fP is an array, \fB${var[1][2]}\fP is the second
character of the first word, but \fB${var[2,4][2]}\fP is the entire third
word (the second word of the range of words two through four of the
original array)\&.  Any number of subscripts may appear\&.
\fB4\&.\fP \fIParameter Name Replacement\fP
The effect of any \fB(P)\fP flag, which treats the value so far as a
parameter name and replaces it with the corresponding value, is applied\&.
\fB5\&.\fP \fIDouble\-Quoted Joining\fP
If the value after this process is an array, and the substitution
appears in double quotes, and no \fB(@)\fP flag is present at the current
level, the words of the value are joined with the first character of the
parameter \fB$IFS\fP, by default a space, between each word (single word
arrays are not modified)\&.  If the \fB(j)\fP flag is present, that is used for
joining instead of \fB$IFS\fP\&.
\fB6\&.\fP \fINested Subscripting\fP
Any remaining subscripts (i\&.e\&. of a nested substitution) are evaluated at
this point, based on whether the value is an array or a scalar\&.  As with
\fB3\&.\fP, multiple subscripts can appear\&.  Note that \fB${foo[2,4][2]}\fP is
thus equivalent to \fB${${foo[2,4]}[2]}\fP and also to
\fB"${${(@)foo[2,4]}[2]}"\fP (the nested substitution returns an array in
both cases), but not to \fB"${${foo[2,4]}[2]}"\fP (the nested substitution
returns a scalar because of the quotes)\&.
\fB7\&.\fP \fIModifiers\fP
Any modifiers, as specified by a trailing `\fB#\fP\&', `\fB%\fP', `\fB/\fP'
(possibly doubled) or by a set of modifiers of the form \fB:\&.\&.\&.\fP (see
the section `Modifiers\&' in the section `History Expansion'), are applied to the words
of the value at this level\&.
\fB8\&.\fP \fICharacter evaluation\fP
Any \fB(#)\fP flag is applied, evaluating the result so far numerically
as a character\&.
\fB9\&.\fP \fILength\fP
Any initial \fB#\fP modifier, i\&.e\&. in the form \fB${#\fP\fIvar\fP\fB}\fP, is
used to evaluate the length of the expression so far\&.
\fB10\&.\fP \fIForced Joining\fP
If the `\fB(j)\fP\&' flag is present, or no `\fB(j)\fP' flag is present but
the string is to be split as given by rules \fB16\&.\fP or \fB17\&.\fP, and joining
did not take place at step \fB5\&.\fP, any words in the value are joined
together using the given string or the first character of \fB$IFS\fP if none\&.
Note that the `\fB(F)\fP\&' flag implicitly supplies a string for joining in this
\fB11\&.\fP \fICase modification\fP
Any case modification from one of the flags \fB(L)\fP, \fB(U)\fP or \fB(C)\fP
is applied\&.
\fB12\&.\fP \fIPrompt evaluation\fP
Any prompt\-style formatting from the \fB(%)\fP family of flags is applied\&.
\fB13\&.\fP \fIQuote application\fP
Any quoting or unquoting using \fB(q)\fP and \fB(Q)\fP and related flags
is applied\&.
\fB14\&.\fP \fIDirectory naming\fP
Any directory name substitution using \fB(D)\fP flag is applied\&.
\fB15\&.\fP \fIVisibility enhancment\fP
Any modifications to make characters visible using the \fB(V)\fP flag
are applied\&.
\fB16\&.\fP \fIForced Splitting\fP
If one of the `\fB(s)\fP\&', `\fB(f)\fP' or `\fB(z)\fP' flags are present, or the `\fB=\fP'
specifier was present (e\&.g\&. \fB${=\fP\fIvar\fP\fB}\fP), the word is split on
occurrences of the specified string, or (for \fB=\fP with neither of the two
flags present) any of the characters in \fB$IFS\fP\&.
\fB17\&.\fP \fIShell Word Splitting\fP
If no `\fB(s)\fP\&', `\fB(f)\fP' or `\fB=\fP' was given, but the word is not
quoted and the option \fBSH_WORD_SPLIT\fP is set, the word is split on
occurrences of any of the characters in \fB$IFS\fP\&.  Note this step, too,
takes place at all levels of a nested substitution\&.
\fB18\&.\fP \fIUniqueness\fP
If the result is an array and the `\fB(u)\fP\&' flag was present, duplicate
elements are removed from the array\&.
\fB19\&.\fP \fIOrdering\fP
If the result is still an array and one of the `\fB(o)\fP\&' or `\fB(O)\fP' flags
was present, the array is reordered\&.
\fB20\&.\fP \fIRe\-Evaluation\fP
Any `\fB(e)\fP\&' flag is applied to the value, forcing it to be re\-examined
for new parameter substitutions, but also for command and arithmetic
\fB21\&.\fP \fIPadding\fP
Any padding of the value by the `\fB(l\&.\fP\fIfill\fP\fB\&.)\fP\&' or
`\fB(r\&.\fP\fIfill\fP\fB\&.)\fP\&' flags is applied\&.
\fB22\&.\fP \fISemantic Joining\fP
In contexts where expansion semantics requires a single word to
result, all words are rejoined with the first character of \fBIFS\fP
between\&.  So in `\fB${(P\fP\fB)${(f\fP\fB)lines}}\fP\&'
the value of \fB${lines}\fP is split at newlines, but then must be
joined again before the \fBP\fP flag can be applied\&.
If a single word is not required, this rule is skipped\&.
\fB23\&.\fP \fIEmpty argument removal\fP
If the substitution does not appear in double quotes, any resulting
zero\-length argument, whether from a scalar or an element of an array,
is elided from the list of arguments inserted into the command line\&.
Strictly speaking, the removal happens later as the same happens with
other forms of substitution; the point to note here is simply that
it occurs after any of the above parameter operations\&.
.SS "Examples"
The flag \fBf\fP is useful to split a double\-quoted substitution line by
line\&.  For example, \fB${(f)"$(<\fP\fIfile\fP\fB)"}\fP
substitutes the contents of \fIfile\fP divided so that each line is
an element of the resulting array\&.  Compare this with the effect of
\fB$\fP\fB(<\fP\fIfile\fP\fB)\fP alone, which divides the file
up by words, or the same inside double quotes, which makes the entire
content of the file a single string\&.
The following illustrates the rules for nested parameter expansions\&.
Suppose that \fB$foo\fP contains the array \fB(bar baz\fP\fB)\fP:
.PD 0
This produces the result \fBb\fP\&.  First, the inner substitution
\fB"${foo}"\fP, which has no array (\fB@\fP) flag, produces a single word
result \fB"bar baz"\fP\&.  The outer substitution \fB"${(@)\&.\&.\&.[1]}"\fP detects
that this is a scalar, so that (despite the `\fB(@)\fP\&' flag) the subscript
picks the first character\&. 
This produces the result `\fBbar\fP\&'\&.  In this case, the inner substitution
\fB"${(@)foo}"\fP produces the array `\fB(bar baz\fP\fB)\fP\&'\&.  The outer
substitution \fB"${\&.\&.\&.[1]}"\fP detects that this is an array and picks the
first word\&.  This is similar to the simple case \fB"${foo[1]}"\fP\&.
As an example of the rules for word splitting and joining, suppose \fB$foo\fP
contains the array `\fB(ax1 bx1\fP\fB)\fP\&'\&.  Then
.PD 0
produces the words `\fBa\fP\&', `\fB1 b\fP' and `\fB1\fP'\&.
produces `\fBa\fP\&', `\fB1\fP', `\fBb\fP' and `\fB1\fP'\&.
produces `\fBa\fP\&' and `\fB b\fP' (note the extra space)\&.  As substitution
occurs before either joining or splitting, the operation  first generates
the modified array \fB(ax bx\fP\fB)\fP, which is joined to give
\fB"ax bx"\fP, and then split to give `\fBa\fP\&', `\fB b\fP' and `'\&.  The final
empty string will then be elided, as it is not in double quotes\&.
A command enclosed in parentheses preceded by a dollar sign, like
`\fB$(\fP\&.\&.\&.\fB)\fP\&', or quoted with grave 
accents, like `\fB`\fP\&.\&.\&.\fB`\fP\&', is replaced with its standard output, with
any trailing newlines deleted\&.
If the substitution is not enclosed in double quotes, the
output is broken into words using the \fBIFS\fP parameter\&.
The substitution `\fB$(cat\fP \fIfoo\fP\fB)\fP\&' may be replaced
by the equivalent but faster `\fB$(<\fP\fIfoo\fP\fB)\fP\&'\&.
In either case, if the option \fBGLOB_SUBST\fP is set,
the output is eligible for filename generation\&.
A string of the form `\fB$[\fP\fIexp\fP\fB]\fP\&' or
`\fB$((\fP\fIexp\fP\fB))\fP\&' is substituted
with the value of the arithmetic expression \fIexp\fP\&.  \fIexp\fP is
subjected to \fIparameter expansion\fP, \fIcommand substitution\fP
and \fIarithmetic expansion\fP before it is evaluated\&.
See the section `Arithmetic Evaluation\&'\&.
A string of the form
is expanded to the individual words
`\fIfooxxbar\fP\&', `\fIfooyybar\fP' and `\fIfoozzbar\fP'\&.
Left\-to\-right order is preserved\&.  This construct
may be nested\&.  Commas may be quoted in order to
include them literally in a word\&.
An expression of the form `\fB{\fP\fIn1\fP\fB\&.\&.\fP\fIn2\fP\fB}\fP\&',
where \fIn1\fP and \fIn2\fP are integers,
is expanded to every number between
\fIn1\fP and \fIn2\fP inclusive\&.  If either number begins with a
zero, all the resulting numbers will be padded with leading zeroes to
that minimum width, but for negative numbers the \fB\-\fP character is also
included in the width\&.  If the numbers are in decreasing order the
resulting sequence will also be in decreasing order\&.
An expression of the form `\fB{\fP\fIn1\fP\fB\&.\&.\fP\fIn2\fP\fB\&.\&.\fP\fIn3\fP\fB}\fP\&',
where \fIn1\fP, \fIn2\fP, and \fIn3\fP are integers,
is expanded as above, but only every \fIn3\fPth number starting from \fIn1\fP
is output\&.  If \fIn3\fP is negative the numbers are output in reverse order,
this is slightly different from simply swapping \fIn1\fP and \fIn2\fP in the case
that the step \fIn3\fP doesn\&'t evenly divide the range\&.  Zero padding can be
specified in any of the three numbers, specifying it in the third can be useful
to pad for example `\fB{\-99\&.\&.100\&.\&.01}\fP\&' which is not possible to specify by putting a
0 on either of the first two numbers (i\&.e\&. pad to two characters)\&.
If a brace expression matches none of the above forms, it is left
unchanged, unless the option \fBBRACE_CCL\fP (an abbreviation for `brace
character class\&') is set\&.
In that case, it is expanded to a list of the individual
characters between the braces sorted into the order of the characters
in the ASCII character set (multibyte characters are not currently
handled)\&.  The syntax is similar to a
\fB[\fP\&.\&.\&.\fB]\fP expression in filename generation:
`\fB\-\fP\&' is treated specially to denote a range of characters, but `\fB^\fP' or
`\fB!\fP\&' as the first character is treated normally\&.  For example,
`\fB{abcdef0\-9}\fP\&' expands to 16 words \fB0 1 2 3 4 5 6 7 8 9 a b c d e f\fP\&.
Note that brace expansion is not part of filename generation (globbing); an
expression such as \fB*/{foo,bar}\fP is split into two separate words
\fB*/foo\fP and \fB*/bar\fP before filename generation takes place\&.  In
particular, note that this is liable to produce a `no match\&' error if
\fIeither\fP of the two expressions does not match; this is to be contrasted
with \fB*/(foo|bar)\fP, which is treated as a single pattern but otherwise
has similar effects\&.
To combine brace expansion with array expansion, see the
\fB${^\fP\fIspec\fP\fB}\fP form described
in the section Parameter Expansion
Each word is checked to see if it begins with an unquoted `\fB~\fP\&'\&.
If it does, then the word up to a `\fB/\fP\&',
or the end of the word if there is no `\fB/\fP\&',
is checked to see if it can be substituted in one of the ways
described here\&.  If so, then the `\fB~\fP\&' and the checked portion are
replaced with the appropriate substitute value\&.
A `\fB~\fP\&' by itself is replaced by the value of \fB$HOME\fP\&.
A `\fB~\fP\&' followed by a `\fB+\fP' or a `\fB\-\fP' is replaced by current
or previous working directory, respectively\&.
A `\fB~\fP\&' followed by a number is replaced by the directory at that
position in the directory stack\&.
`\fB~0\fP\&' is equivalent to `\fB~+\fP',
and `\fB~1\fP\&' is the top of the stack\&.
`\fB~+\fP\&' followed by a number is replaced by the directory at that
position in the directory stack\&.
`\fB~+0\fP\&' is equivalent to `\fB~+\fP',
and `\fB~+1\fP\&' is the top of the stack\&.
`\fB~\-\fP\&' followed by a number is replaced by the directory that
many positions from the bottom of the stack\&.
`\fB~\-0\fP\&' is the bottom of the stack\&.
option exchanges the effects of `\fB~+\fP\&' and `\fB~\-\fP' where they are
followed by a number\&.
.SS "Dynamic named directories"
The feature described here is only available if the shell function
\fBzsh_directory_name\fP exists\&.
A `\fB~\fP\&' followed by a string \fInamstr\fP in unquoted square brackets is
treated specially as a dynamic directory name\&.  Note that the first
unquoted closing square bracket always terminates \fInamstr\fP\&.  The shell
function is passed two arguments: the string \fBn\fP (for name) and
\fInamstr\fP\&.  It should either set the array \fBreply\fP to a single element
which is the directory corresponding to the name and return status zero
(executing an assignment as the last statement is usually sufficient), or
it should return status non\-zero\&.  In the former case the element of reply
is used as the directory; in the latter case the substitution is deemed to
have failed and \fBNOMATCH\fP handling is applied if the option is set\&.
The function \fBzsh_directory_name\fP is also used to see if a directory can
be turned into a name, for example when printing the directory stack or
when expanding \fB%~\fP in prompts\&.  In this case the function is passed two
arguments: the string \fBd\fP (for directory) and the candidate for dynamic
naming\&.  The function should either return non\-zero status, if the
directory cannot be named by the function, or it should set the array reply
to consist of two elements: the first is the dynamic name for the directory
(as would appear within `\fB~[\fP\fI\&.\&.\&.\fP\fB]\fP\&'), and the second is the
prefix length of the directory to be replaced\&.  For example, if the trial
directory is \fB/home/myname/src/zsh\fP and the dynamic name for
\fB/home/myname/src\fP (which has 16 characters) is \fBs\fP, then the function
\fBreply=(s 16)\fP
The directory name so returned is compared with possible static names for
parts of the directory path, as described below; it is used if the prefix
length matched (16 in the example) is longer than that matched by any
static name\&.
The completion system calls `\fBzsh_directory_name c\fP\&' in order to
complete dynamic names for directories\&.  The code for this should be
as for any other completion function as described in
As a working example, here is a function that expands any dynamic names
beginning with the string \fBp:\fP to directories below
\fB/home/pws/perforce\fP\&.  In this simple case a static name for the
directory would be just as effective\&.
\fBzsh_directory_name() {
  emulate \-L zsh
  setopt extendedglob
  local \-a match mbegin mend
  if [[ $1 = d ]]; then
    # turn the directory into a name
    if [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then
      typeset \-ga reply
      reply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) )
      return 1
  elif [[ $1 = n ]]; then
    # turn the name into a directory
    [[ $2 != (#b)p:(?*) ]] && return 1
    typeset \-ga reply
  elif [[ $1 = c ]]; then
    # complete names
    local expl
    local \-a dirs
    _wanted dynamic\-dirs expl \&'dynamic directory' compadd \-S\e] \-a dirs
    return 1
  return 0
.SS "Static named directories"
A `\fB~\fP\&' followed by anything not already covered consisting
of any number of alphanumeric characters or underscore (`\fB_\fP\&'),
hyphen (`\fB\-\fP\&'), or dot (`\fB\&.\fP') is looked up as a
named directory, and replaced by the value of that named directory if found\&.
Named directories are typically home directories for users on the system\&.
They may also be defined if the text after the `\fB~\fP\&' is the name
of a string shell parameter whose value begins with a `\fB/\fP\&'\&.
Note that trailing slashes will be removed from the path to the directory
(though the original parameter is not modified)\&.
It is also possible to define directory names using the \fB\-d\fP option to the
\fBhash\fP builtin\&.
In certain circumstances (in prompts, for instance), when the shell
prints a path, the path is checked to see if it has a named
directory as its prefix\&.  If so, then the prefix portion
is replaced with a `\fB~\fP\&' followed by the name of the directory\&.
The shortest way of referring to the directory is used,
with ties broken in favour of using a named directory,
except when the directory is \fB/\fP itself\&.  The parameters \fB$PWD\fP and
\fB$OLDPWD\fP are never abbreviated in this fashion\&.
.SS "`=\&' expansion"
If a word begins with an unquoted `\fB=\fP\&'
and the \fBEQUALS\fP option is set,
the remainder of the word is taken as the
name of a command\&.  If a command
exists by that name, the word is replaced
by the full pathname of the command\&.
.SS "Notes"
Filename expansion is performed on the right hand side of a parameter
assignment, including those appearing after commands of the
\fBtypeset\fP family\&.  In this case, the right hand side will be treated
as a colon\-separated list in the manner of the \fBPATH\fP parameter,
so that a `\fB~\fP\&' or an `\fB=\fP' following a `\fB:\fP' is eligible for expansion\&.
All such behaviour can be
disabled by quoting the `\fB~\fP\&', the `\fB=\fP', or the whole expression (but not
simply the colon); the \fBEQUALS\fP option is also respected\&.
If the option \fBMAGIC_EQUAL_SUBST\fP is set, any unquoted shell
argument in the form `\fIidentifier\fP\fB=\fP\fIexpression\fP\&' becomes eligible
for file expansion as described in the previous paragraph\&.  Quoting the
first `\fB=\fP\&' also inhibits this\&.
If a word contains an unquoted instance of one of the characters
`\fB*\fP\&', `\fB(\fP', `\fB|\fP', `\fB<\fP', `\fB[\fP', or `\fB?\fP', it is regarded
as a pattern for filename generation, unless the \fBGLOB\fP option is unset\&.
If the \fBEXTENDED_GLOB\fP option is set,
the `\fB^\fP\&' and `\fB#\fP' characters also denote a pattern; otherwise
they are not treated specially by the shell\&.
The word is replaced with a list of sorted filenames that match
the pattern\&.  If no matching pattern is found, the shell gives
an error message, unless the \fBNULL_GLOB\fP option is set,
in which case the word is deleted; or unless the \fBNOMATCH\fP
option is unset, in which case the word is left unchanged\&.
In filename generation,
the character `\fB/\fP\&' must be matched explicitly;
also, a `\fB\&.\fP\&' must be matched
explicitly at the beginning of a pattern or after a `\fB/\fP\&', unless the
\fBGLOB_DOTS\fP option is set\&.
No filename generation pattern
matches the files `\fB\&.\fP\&' or `\fB\&.\&.\fP'\&.  In other instances of pattern
matching, the `\fB/\fP\&' and `\fB\&.\fP' are not treated specially\&.
.SS "Glob Operators"
.PD 0
Matches any string, including the null string\&.
Matches any character\&.
Matches any of the enclosed characters\&.  Ranges of characters
can be specified by separating two characters by a `\fB\-\fP\&'\&.
A `\fB\-\fP\&' or `\fB]\fP' may be matched by including it as the
first character in the list\&.
There are also several named classes of characters, in the form
`\fB[:\fP\fIname\fP\fB:]\fP\&' with the following meanings\&.
The first set use the macros provided by
the operating system to test for the given character combinations,
including any modifications due to local language settings, see
.PD 0
The character is alphanumeric
The character is alphabetic
The character is 7\-bit, i\&.e\&. is a single\-byte character without
the top bit set\&.
The character is either space or tab
The character is a control character
The character is a decimal digit
The character is a printable character other than whitespace
The character is a lowercase letter
The character is printable
The character is printable but neither alphanumeric nor whitespace
The character is whitespace
The character is an uppercase letter
The character is a hexadecimal digit
Another set of named classes is handled internally by the shell and
is not sensitive to the locale:
.PD 0
The character is allowed to form part of a shell identifier, such
as a parameter name
The character is used as an input field separator, i\&.e\&. is contained in the
\fBIFS\fP parameter
The character is an IFS white space character; see the documentation
for \fBIFS\fP in
the \fIzshparam\fP(1) manual page\&.
The character is treated as part of a word; this test is sensitive
to the value of the \fBWORDCHARS\fP parameter
Note that the square brackets are additional
to those enclosing the whole set of characters, so to test for a
single alphanumeric character you need `\fB[[:alnum:]]\fP\&'\&.  Named
character sets can be used alongside other types,
e\&.g\&. `\fB[[:alpha:]0\-9]\fP\&'\&.
.PD 0
Like \fB[\fP\&.\&.\&.\fB]\fP, except that it matches any character which is
not in the given set\&.
Matches any number in the range \fIx\fP to \fIy\fP, inclusive\&.
Either of the numbers may be omitted to make the range open\-ended;
hence `\fB<\->\fP\&' matches any number\&.  To match individual digits, the
\fB[\fP\&.\&.\&.\fB]\fP form is more efficient\&.
Be careful when using other wildcards adjacent to patterns of this form;
for example, \fB<0\-9>*\fP will actually match any number whatsoever at the
start of the string, since the `\fB<0\-9>\fP\&' will match the first digit, and
the `\fB*\fP\&' will match any others\&.  This is a trap for the unwary, but is
in fact an inevitable consequence of the rule that the longest possible
match always succeeds\&.  Expressions such as `\fB<0\-9>[^[:digit:]]*\fP\&' can be
used instead\&.
Matches the enclosed pattern\&.  This is used for grouping\&.
If the \fBKSH_GLOB\fP option is set, then a
`\fB@\fP\&', `\fB*\fP', `\fB+\fP', `\fB?\fP' or `\fB!\fP' immediately preceding
the `\fB(\fP\&' is treated specially, as detailed below\&. The option
\fBSH_GLOB\fP prevents bare parentheses from being used in this way, though
the \fBKSH_GLOB\fP option is still available\&.
Note that grouping cannot extend over multiple directories: it is an error
to have a `\fB/\fP\&' within a group (this only applies for patterns used in
filename generation)\&.  There is one exception:  a group of the form
\fB(\fP\fIpat\fP\fB/)#\fP appearing as a complete path segment can
match a sequence of directories\&.  For example, \fBfoo/(a*/)#bar\fP matches
\fBfoo/bar\fP, \fBfoo/any/bar\fP, \fBfoo/any/anyother/bar\fP, and so on\&.
Matches either \fIx\fP or \fIy\fP\&.
This operator has lower precedence than any other\&.
The `\fB|\fP\&' character
must be within parentheses, to avoid interpretation as a pipeline\&.
(Requires \fBEXTENDED_GLOB\fP to be set\&.)
Matches anything except the pattern \fIx\fP\&.
This has a higher precedence than `\fB/\fP\&', so `\fB^foo/bar\fP'
will search directories in `\fB\&.\fP\&' except `\fB\&./foo\fP'
for a file named `\fBbar\fP\&'\&.
(Requires \fBEXTENDED_GLOB\fP to be set\&.)
Match anything that matches the pattern \fIx\fP but does not match \fIy\fP\&.
This has lower precedence than any operator except `\fB|\fP\&', so
`\fB*/*~foo/bar\fP\&' will search for all files in all directories in `\fB\&.\fP'
and then exclude `\fBfoo/bar\fP\&' if there was such a match\&.
Multiple patterns can be excluded by
In the exclusion pattern (\fIy\fP), `\fB/\fP\&' and `\fB\&.\fP' are not treated
specially the way they usually are in globbing\&.
(Requires \fBEXTENDED_GLOB\fP to be set\&.)
Matches zero or more occurrences of the pattern \fIx\fP\&.
This operator has high precedence; `\fB12#\fP\&' is equivalent to `\fB1(2#)\fP',
rather than `\fB(12)#\fP\&'\&.  It is an error for an unquoted `\fB#\fP' to follow
something which cannot be repeated; this includes an empty string, a
pattern already followed by `\fB##\fP\&', or parentheses when part of a
\fBKSH_GLOB\fP pattern (for example, `\fB!(\fP\fIfoo\fP\fB)#\fP\&' is
invalid and must be replaced by
(Requires \fBEXTENDED_GLOB\fP to be set\&.)
Matches one or more occurrences of the pattern \fIx\fP\&.
This operator has high precedence; `\fB12##\fP\&' is equivalent to `\fB1(2##)\fP',
rather than `\fB(12)##\fP\&'\&.  No more than two active `\fB#\fP' characters may
appear together\&.  (Note the potential clash with glob qualifiers in the
form `\fB1(2##)\fP\&' which should therefore be avoided\&.)
.SS "ksh\-like Glob Operators"
If the \fBKSH_GLOB\fP option is set, the effects of parentheses can be
modified by a preceding `\fB@\fP\&', `\fB*\fP', `\fB+\fP', `\fB?\fP' or `\fB!\fP'\&.
This character need not be unquoted to have special effects,
but the `\fB(\fP\&' must be\&.
.PD 0
Match the pattern in the parentheses\&.  (Like `\fB(\fP\&.\&.\&.\fB)\fP\&'\&.)
Match any number of occurrences\&.  (Like `\fB(\fP\&.\&.\&.\fB)#\fP\&'\&.)
Match at least one occurrence\&.  (Like `\fB(\fP\&.\&.\&.\fB)##\fP\&'\&.)
Match zero or one occurrence\&.  (Like `\fB(|\fP\&.\&.\&.\fB)\fP\&'\&.)
Match anything but the expression in parentheses\&.
(Like `\fB(^(\fP\&.\&.\&.\fB))\fP\&'\&.)
.SS "Precedence"
The precedence of the operators given above is (highest) `\fB^\fP\&', `\fB/\fP',
`\fB~\fP\&', `\fB|\fP' (lowest); the
remaining operators are simply treated from left to right as part of a
string, with `\fB#\fP\&' and `\fB##\fP' applying to the shortest possible
preceding unit (i\&.e\&. a character, `\fB?\fP\&', `\fB[\fP\&.\&.\&.\fB]\fP',
`\fB<\fP\&.\&.\&.\fB>\fP\&', or a parenthesised expression)\&.  As mentioned
above, a `\fB/\fP\&' used as a directory separator may not appear inside
parentheses, while a `\fB|\fP\&' must do so; in patterns used in other contexts
than filename generation (for example, in \fBcase\fP statements and tests
within `\fB[[\fP\&.\&.\&.\fB]]\fP\&'), a `\fB/\fP' is not special; and `\fB/\fP' is also
not special after a `\fB~\fP\&' appearing outside parentheses in a filename
.SS "Globbing Flags"
There are various flags which affect any text to their right up to the
end of the enclosing group or to the end of the pattern; they require
the \fBEXTENDED_GLOB\fP option\&. All take the form
\fB(#\fP\fIX\fP\fB)\fP where \fIX\fP may have one of the following
.PD 0
Case insensitive:  upper or lower case characters in the pattern match
upper or lower case characters\&.
Lower case characters in the pattern match upper or lower case
characters; upper case characters in the pattern still only match
upper case characters\&.
Case sensitive:  locally negates the effect of \fBi\fP or \fBl\fP from
that point on\&.
Activate backreferences for parenthesised groups in the pattern;
this does not work in filename generation\&.  When a pattern with a set of
active parentheses is matched, the strings matched by the groups are
stored in the array \fB$match\fP, the indices of the beginning of the matched
parentheses in the array \fB$mbegin\fP, and the indices of the end in the array
\fB$mend\fP, with the first element of each array corresponding to the first
parenthesised group, and so on\&.  These arrays are not otherwise special to
the shell\&.  The indices use the same convention as does parameter
substitution, so that elements of \fB$mend\fP and \fB$mbegin\fP may be used in
subscripts; the \fBKSH_ARRAYS\fP option is respected\&.  Sets of globbing flags
are not considered parenthesised groups; only the first nine active
parentheses can be referenced\&.
For example,
\fBfoo="a string with a message"
if [[ $foo = (a|an)\&' '(#b)(*)' '* ]]; then
  print ${foo[$mbegin[1],$mend[1]]}
prints `\fBstring with a\fP\&'\&.  Note that the first parenthesis is before the
\fB(#b)\fP and does not create a backreference\&.
Backreferences work with all forms of pattern matching other than filename
generation, but note that when performing matches on an entire array, such
as \fB${\fP\fIarray\fP\fB#\fP\fIpattern\fP\fB}\fP, or a global substitution, such
as \fB${\fP\fIparam\fP\fB//\fP\fIpat\fP\fB/\fP\fIrepl\fP\fB}\fP, only the data for the
last match remains available\&.  In the case of global replacements this may
still be useful\&.  See the example for the \fBm\fP flag below\&.
The numbering of backreferences strictly follows the order of the opening
parentheses from left to right in the pattern string, although sets of
parentheses may be nested\&.  There are special rules for parentheses followed
by `\fB#\fP\&' or `\fB##\fP'\&.  Only the last match of the parenthesis is
remembered: for example, in `\fB[[ abab = (#b)([ab])# ]]\fP\&', only the final
`\fBb\fP\&' is stored in \fBmatch[1]\fP\&.  Thus extra parentheses may be necessary
to match the complete segment: for example, use
`\fBX((ab|cd)#)Y\fP\&' to match
a whole string of either `\fBab\fP\&' or `\fBcd\fP' between `\fBX\fP' and `\fBY\fP',
using the value of \fB$match[1]\fP rather than \fB$match[2]\fP\&.
If the match fails none of the parameters is altered, so in some cases it
may be necessary to initialise them beforehand\&.  If some of the
backreferences fail to match \-\- which happens if they are in an alternate
branch which fails to match, or if they are followed by \fB#\fP and matched
zero times \-\- then the matched string is set to the empty string, and the
start and end indices are set to \-1\&.
Pattern matching with backreferences is slightly slower than without\&.
Deactivate backreferences, negating the effect of the \fBb\fP flag from that
point on\&.
The flag \fB(#c\fP\fIN\fP\fB,\fP\fIM\fP\fB)\fP can be used anywhere
that the \fB#\fP or \fB##\fP operators can be used; it cannot be combined
with other globbing flags and a bad pattern error occurs if it is
misplaced\&.  It is equivalent to the form \fB{\fP\fIN\fP\fB,\fP\fIM\fP\fB}\fP in
regular expressions\&.  The previous character or group is required to
match between \fIN\fP and \fIM\fP times, inclusive\&.  The form
\fB(#c\fP\fIN\fP\fB)\fP requires exactly \fBN\fP matches;
\fB(#c,\fP\fIM\fP\fB)\fP is equivalent to specifying \fIN\fP as 0;
\fB(#c\fP\fIN\fP\fB,)\fP specifies that there is no maximum limit
on the number of matches\&.
Set references to the match data for the entire string matched; this is
similar to backreferencing and does not work in filename generation\&.  The
flag must be in effect at the end of the pattern, i\&.e\&. not local to a
group\&. The parameters \fB$MATCH\fP,  \fB$MBEGIN\fP and \fB$MEND\fP will be set to
the string matched and to the indices of the beginning and end of the
string, respectively\&.  This is most useful in parameter substitutions, as
otherwise the string matched is obvious\&.
For example,
\fBarr=(veldt jynx grimps waqf zho buck)
print ${arr//(#m)[aeiou]/${(U)MATCH}}\fP
forces all the matches (i\&.e\&. all vowels) into uppercase, printing
`\fBvEldt jynx grImps wAqf zhO bUck\fP\&'\&.
Unlike backreferences, there is no speed penalty for using match
references, other than the extra substitutions required for the
replacement strings in cases such as the example shown\&.
Deactivate the \fBm\fP flag, hence no references to match data will be
Approximate matching: \fInum\fP errors are allowed in the string matched by
the pattern\&.  The rules for this are described in the next subsection\&.
\fBs\fP, \fBe\fP
Unlike the other flags, these have only a local effect, and each must
appear on its own:  `\fB(#s)\fP\&' and `\fB(#e)\fP' are the only valid forms\&.
The `\fB(#s)\fP\&' flag succeeds only at the start of the test string, and the
`\fB(#e)\fP\&' flag succeeds only at the end of the test string; they
correspond to `\fB^\fP\&' and `\fB$\fP' in standard regular expressions\&.  They
are useful for matching path segments in patterns other than those in
filename generation (where path segments are in any case treated
separately)\&.  For example, `\fB*((#s)|/)test((#e)|/)*\fP\&' matches
a path segment `\fBtest\fP\&' in any of the following strings: \fBtest\fP,
\fBtest/at/start\fP, \fBat/end/test\fP, \fBin/test/middle\fP\&.
Another use is in parameter substitution; for example
`\fB${array/(#s)A*Z(#e)}\fP\&' will remove only elements of an
array which
match the complete pattern `\fBA*Z\fP\&'\&.  There are other ways of performing
many operations of this type, however the combination of the substitution
operations `\fB/\fP\&' and `\fB//\fP' with the `\fB(#s)\fP' and `\fB(#e)\fP' flags
provides a single simple and memorable method\&.
Note that assertions of the form `\fB(^(#s))\fP\&' also work, i\&.e\&. match
anywhere except at the start of the string, although this actually means
`anything except a zero\-length portion at the start of the string\&'; you
need to use `\fB(""~(#s))\fP\&' to match a zero\-length portion of the string
not at the start\&.
A `\fBq\fP\&' and everything up to the closing parenthesis of the globbing
flags are ignored by the pattern matching code\&.  This is intended to
support the use of glob qualifiers, see below\&.  The result is that
the pattern `\fB(#b)(*)\&.c(#q\&.)\fP\&' can be used both for globbing
and for
matching against a string\&.  In the former case, the `\fB(#q\&.)\fP\&' will be
treated as a glob qualifier and the `\fB(#b)\fP\&' will not be useful, while in
the latter case the `\fB(#b)\fP\&' is useful for backreferences and the
`\fB(#q\&.)\fP\&' will be ignored\&.  Note that colon modifiers in the glob
qualifiers are also not applied in ordinary pattern matching\&.
Respect the current locale in determining the presence of multibyte
characters in a pattern, provided the shell was compiled with 
\fBMULTIBYTE_SUPPORT\fP\&.  This overrides the \fBMULTIBYTE\fP
option; the default behaviour is taken from the option\&.  Compare \fBU\fP\&.
(Mnemonic: typically multibyte characters are from Unicode in the UTF\-8
encoding, although any extension of ASCII supported by the system
library may be used\&.)
All characters are considered to be a single byte long\&.  The opposite
of \fBu\fP\&.  This overrides the \fBMULTIBYTE\fP option\&.
For example, the test string \fBfooxx\fP can be matched by the pattern
\fB(#i\fP\fB)FOOXX\fP, but not by \fB(#l\fP\fB)FOOXX\fP,
\fB(#i\fP\fB)FOO\fP\fB(#I\fP\fB)XX\fP or
\fB((#i\fP\fB)FOOX\fP\fB)X\fP\&.  The string
\fB(#ia2\fP\fB)readme\fP specifies case\-insensitive matching of
\fBreadme\fP with up to two errors\&.
When using the ksh syntax for grouping both \fBKSH_GLOB\fP and
\fBEXTENDED_GLOB\fP must be set and the left parenthesis should be
preceded by \fB@\fP\&.  Note also that the flags do not affect letters
inside \fB[\&.\&.\&.]\fP groups, in other words \fB(#i\fP\fB)[a\-z]\fP
still matches only lowercase letters\&.  Finally, note that when
examining whole paths case\-insensitively every directory must be
searched for all files which match, so that a pattern of the form
\fB(#i\fP\fB)/foo/bar/\&.\&.\&.\fP is potentially slow\&.
.SS "Approximate Matching"
When matching approximately, the shell keeps a count of the errors found,
which cannot exceed the number specified in the
\fB(#a\fP\fInum\fP\fB)\fP flags\&.  Four types of error are recognised:
.PD 0
Different characters, as in \fBfooxbar\fP and \fBfooybar\fP\&.
Transposition of characters, as in \fBbanana\fP and \fBabnana\fP\&.
A character missing in the target string, as with the pattern \fBroad\fP and
target string \fBrod\fP\&.
An extra character appearing in the target string, as with \fBstove\fP
and \fBstrove\fP\&.
Thus, the pattern \fB(#a3\fP\fB)abcd\fP matches \fBdcba\fP, with the
errors occurring by using the first rule twice and the second once,
grouping the string as \fB[d][cb][a]\fP and \fB[a][bc][d]\fP\&.
Non\-literal parts of the pattern must match exactly, including characters
in character ranges: hence \fB(#a1\fP\fB)???\fP  matches strings of
length four, by applying rule 4 to an empty part of the pattern, but not
strings of length two, since all the \fB?\fP must match\&.  Other characters
which must match exactly are initial dots in filenames (unless the
\fBGLOB_DOTS\fP option is set), and all slashes in filenames, so that
\fBa/bc\fP is two errors from \fBab/c\fP (the slash cannot be transposed with
another character)\&.  Similarly, errors are counted separately for
non\-contiguous strings in the pattern, so that \fB(ab|cd\fP\fB)ef\fP
is two errors from \fBaebf\fP\&.
When using exclusion via the \fB~\fP operator, approximate matching is
treated entirely separately for the excluded part and must be activated
separately\&.  Thus, \fB(#a1\fP\fB)README~READ_ME\fP matches
\fBREAD\&.ME\fP but not \fBREAD_ME\fP, as the trailing \fBREAD_ME\fP is matched
without approximation\&.  However,
does not match any pattern of the form \fBREAD\fP\fI?\fP\fBME\fP as all
such forms are now excluded\&.
Apart from exclusions, there is only one overall error count; however, the
maximum errors allowed may be altered locally, and this can be delimited by
grouping\&.  For example,
allows one error in total, which may not occur in the \fBdog\fP section, and
the pattern
is equivalent\&.  Note that the point at which an error is first found is the
crucial one for establishing whether to use approximation; for example,
\fB(#a1)abc(#a0)xyz\fP will not match \fBabcdxyz\fP, because the
error occurs at the `\fBx\fP\&', where approximation is turned off\&.
Entire path segments may be matched approximately, so that
`\fB(#a1)/foo/d/is/available/at/the/bar\fP\&' allows one error in any path
segment\&.  This is much less efficient than without the \fB(#a1)\fP, however,
since every directory in the path must be scanned for a possible
approximate match\&.  It is best to place the \fB(#a1)\fP after any path
segments which are known to be correct\&.
.SS "Recursive Globbing"
A pathname component of the form `\fB(\fP\fIfoo\fP\fB/)#\fP\&'
matches a path consisting of zero or more directories
matching the pattern \fIfoo\fP\&.
As a shorthand, `\fB**/\fP\&' is equivalent to `\fB(*/)#\fP'; note that this
therefore matches files in the current directory as well as
\fBls (*/)#bar\fP
\fBls **/bar\fP
does a recursive directory search for files named `\fBbar\fP\&' (potentially
including the file `\fBbar\fP\&' in the current directory)\&.  This form does not
follow symbolic links; the alternative form `\fB***/\fP\&' does, but is
otherwise identical\&.  Neither of these can be combined with other forms of
globbing within the same path segment; in that case, the `\fB*\fP\&'
operators revert to their usual effect\&.
.SS "Glob Qualifiers"
Patterns used for filename generation may end in a
list of qualifiers enclosed in parentheses\&.
The qualifiers specify which filenames that otherwise match the given pattern
will be inserted in the argument list\&.
If the option \fBBARE_GLOB_QUAL\fP is set, then a trailing set of parentheses
containing no `\fB|\fP\&' or `\fB(\fP' characters (or `\fB~\fP' if it is special)
is taken as a set of
glob qualifiers\&.  A glob subexpression that would normally be taken as glob
qualifiers, for example `\fB(^x)\fP\&', can be forced to be treated as part of
the glob pattern by doubling the parentheses, in this case producing
If the option \fBEXTENDED_GLOB\fP is set, a different syntax for glob
qualifiers is available, namely `\fB(#qx)\fP\&' where \fBx\fP is any of the same
glob qualifiers used in the other format\&.  The qualifiers must still appear
at the end of the pattern\&.  However, with this syntax multiple glob
qualifiers may be chained together\&.  They are treated as a logical AND of
the individual sets of flags\&.  Also, as the syntax is unambiguous, the
expression will be treated as glob qualifiers just as long any parentheses
contained within it are balanced; appearance of `\fB|\fP\&', `\fB(\fP' or
`\fB~\fP\&' does not negate the effect\&.  Note that qualifiers will be
recognised in this form even if a bare glob qualifier exists at the end of
the pattern, for example `\fB*(#q*)(\&.)\fP\&' will recognise executable regular
files if both options are set; however, mixed syntax should probably be
avoided for the sake of clarity\&.
A qualifier may be any one of the following:
.PD 0
`full\&' (i\&.e\&. non\-empty) directories\&.  Note that the
opposite sense \fB(^F\fP\fB)\fP expands to empty directories
and all non\-directories\&.  Use \fB(/^F\fP\fB)\fP for
empty directories\&.
plain files
symbolic links
named pipes (FIFOs)
executable plain files (0100)
device files (character or block special)
block special files
character special files
owner\-readable files (0400)
owner\-writable files (0200)
owner\-executable files (0100)
group\-readable files (0040)
group\-writable files (0020)
group\-executable files (0010)
world\-readable files (0004)
world\-writable files (0002)
world\-executable files (0001)
setuid files (04000)
setgid files (02000)
files with the sticky bit (01000)
files with access rights matching \fIspec\fP\&. This \fIspec\fP may be a
octal number optionally preceded by a `\fB=\fP\&', a `\fB+\fP', or a
`\fB\-\fP\&'\&. If none of these characters is given, the behavior is the
same as for `\fB=\fP\&'\&. The octal number describes the mode bits to be
expected, if combined with a `\fB=\fP\&', the value given must match the
file\-modes exactly, with a `\fB+\fP\&', at least the bits in the
given number must be set in the file\-modes, and with a `\fB\-\fP\&', the
bits in the number must not be set\&. Giving a `\fB?\fP\&' instead of a
octal digit anywhere in the number ensures that the corresponding bits 
in the file\-modes are not checked, this is only useful in combination
with `\fB=\fP\&'\&.
If the qualifier `\fBf\fP\&' is followed by any other character anything
up to the next matching character (`\fB[\fP\&', `\fB{\fP', and `\fB<\fP' match 
`\fB]\fP\&', `\fB}\fP', and `\fB>\fP' respectively, any other character
matches itself) is taken as a list of comma\-separated
\fIsub\-spec\fPs\&. Each \fIsub\-spec\fP may be either an octal number as
described above or a list of any of the characters `\fBu\fP\&', `\fBg\fP',
`\fBo\fP\&', and `\fBa\fP', followed by a `\fB=\fP', a `\fB+\fP', or a
`\fB\-\fP\&', followed by a list of any of the characters `\fBr\fP', `\fBw\fP', 
`\fBx\fP\&', `\fBs\fP', and `\fBt\fP', or an octal digit\&. The first list of
characters specify which access rights are to be checked\&. If a `\fBu\fP\&'
is given, those for the owner of the file are used, if a `\fBg\fP\&' is
given, those of the group are checked, a `\fBo\fP\&' means to test those
of other users, and the `\fBa\fP\&' says to test all three groups\&. The
`\fB=\fP\&', `\fB+\fP', and `\fB\-\fP' again says how the modes are to be
checked and have the same meaning as described for the first form
above\&. The second list of characters finally says which access rights
are to be expected: `\fBr\fP\&' for read access, `\fBw\fP' for write access, 
`\fBx\fP\&' for the right to execute the file (or to search a directory),
`\fBs\fP\&' for the setuid and setgid bits, and `\fBt\fP' for the sticky
Thus, `\fB*(f70?)\fP\&' gives the files for which the owner has read,
write, and execute permission, and for which other group members have
no rights, independent of the permissions for other users\&. The pattern
`\fB*(f\-100)\fP\&' gives all files for which the owner does not have
execute permission, and `\fB*(f:gu+w,o\-rx:)\fP\&' gives the files for which 
the owner and the other members of the group have at least write
permission, and for which other users don\&'t have read or execute
.PD 0
The \fIstring\fP will be executed as shell code\&.  The filename will be
included in the list if and only if the code returns a zero status (usually
the status of the last command)\&.
In the first form, the first character after the `\fBe\fP\&'
will be used as a separator and anything up to the next matching separator
will be taken  as the \fIstring\fP; `\fB[\fP\&', `\fB{\fP', and `\fB<\fP' match
`\fB]\fP\&', `\fB}\fP', and `\fB>\fP', respectively, while any other character
matches itself\&. Note that expansions must be quoted in the \fIstring\fP
to prevent them from being expanded before globbing is done\&.
\fIstring\fP is then executed as shell code\&.  The string \fBglobqual\fP
is appended to the array \fBzsh_eval_context\fP the duration of
During the execution of \fIstring\fP the filename currently being tested is
available in the parameter \fBREPLY\fP; the parameter may be altered to
a string to be inserted into the list instead of the original
filename\&.  In addition, the parameter \fBreply\fP may be set to an array or a
string, which overrides the value of \fBREPLY\fP\&.  If set to an array, the
latter is inserted into the command line word by word\&.
For example, suppose a directory contains a single file `\fBlonely\fP\&'\&.  Then
the expression `\fB*(e:\&'reply=(${REPLY}{1,2})':)\fP' will cause the words
`\fBlonely1 lonely2\fP\&' to be inserted into the command line\&.  Note the
quotation marks\&.
The form \fB+\fP\fIcmd\fP has the same effect, but no delimiters appear
around \fIcmd\fP\&.  Instead, \fIcmd\fP is taken as the longest sequence of
characters following the \fB+\fP that are alphanumeric or underscore\&.
Typically \fIcmd\fP will be the name of a shell function that contains the
appropriate test\&.  For example,
\fBnt() { [[ $REPLY \-nt $NTREF ]] }
ls \-l *(+nt)\fP
lists all files in the directory that have been modified more recently than
files on the device \fIdev\fP
files having a link count less than \fIct\fP (\fB\-\fP), greater than
\fIct\fP (\fB+\fP), or equal to \fIct\fP
files owned by the effective user ID
files owned by the effective group ID
files owned by user ID \fIid\fP if that is a number\&.  Otherwise,
\fIid\fP specifies a user name: the
character after the `\fBu\fP\&' will be taken as a separator and the string
between it and the next matching separator will be taken as a user name\&.
The starting separators `\fB[\fP\&', `\fB{\fP', and `\fB<\fP'
match the final separators `\fB]\fP\&', `\fB}\fP', and `\fB>\fP', respectively;
any other character matches itself\&.  The selected files are those
owned by this user\&.  For example, `\fBu:foo:\fP\&' or `\fBu[foo]\fP' selects
files owned by user `\fBfoo\fP\&'\&.
like \fBu\fP\fIid\fP but with group IDs or names
files accessed exactly \fIn\fP days ago\&.  Files accessed within the last
\fIn\fP days are selected using a negative value for \fIn\fP (\fB\-\fP\fIn\fP)\&.
Files accessed more than \fIn\fP days ago are selected by a positive \fIn\fP
value (\fB+\fP\fIn\fP)\&.  Optional unit specifiers `\fBM\fP\&', `\fBw\fP',
`\fBh\fP\&', `\fBm\fP' or `\fBs\fP' (e\&.g\&. `\fBah5\fP') cause the check to be
performed with months (of 30 days), weeks, hours, minutes or seconds
instead of days, respectively\&.
Any fractional part of the difference between the access time and the
current part in the appropriate units is ignored in the comparison\&.  For
instance, `\fBecho *(ah\-5)\fP\&' would echo files accessed within the last
five hours, while `\fBecho *(ah+5)\fP\&' would echo files accessed at least
six hours ago, as times strictly between five and six hours are treated
as five hours\&.
like the file access qualifier, except that it uses the file modification
like the file access qualifier, except that it uses the file inode change
files less than \fIn\fP bytes (\fB\-\fP), more than \fIn\fP bytes (\fB+\fP), or
exactly \fIn\fP bytes in length\&.
If this flag is directly followed by a `\fBk\fP\&' (`\fBK\fP'), `\fBm\fP'
(`\fBM\fP\&'), or `\fBp\fP' (`\fBP\fP') (e\&.g\&. `\fBLk\-50\fP') the check is performed
with kilobytes, megabytes, or blocks (of 512 bytes) instead\&.  In this
case a file is regarded as "exactly" the size if the file size rounded up
to the next unit is equal to the test size\&.  Hence `\fB*(Lm1)\fP\&'
matches files from 1 byte up to 1 Megabyte inclusive\&.  Note also that
the set of files "less than" the test size only includes files that would
not match the equality test; hence `\fB*(Lm\-1)\fP\&' only matches
files of zero size\&.
negates all qualifiers following it
toggles between making the qualifiers work on symbolic links (the
default) and the files they point to
sets the \fBMARK_DIRS\fP option for the current pattern
appends a trailing qualifier mark to the filenames, analogous to the
\fBLIST_TYPES\fP option, for the current pattern (overrides \fBM\fP)
sets the \fBNULL_GLOB\fP option for the current pattern
sets the \fBGLOB_DOTS\fP option for the current pattern
sets the \fBNUMERIC_GLOB_SORT\fP option for the current pattern
specifies how the names of the files should be sorted\&. If \fIc\fP is
\fBn\fP they are sorted by name (the default); if it is \fBL\fP they
are sorted depending on the size (length) of the files; if \fBl\fP
they are sorted by the number of links; if \fBa\fP, \fBm\fP, or \fBc\fP
they are sorted by the time of the last access, modification, or
inode change respectively; if \fBd\fP, files in subdirectories appear before
those in the current directory at each level of the search \-\- this is best
combined with other criteria, for example `\fBodon\fP\&' to sort on names for
files within the same directory; if \fBN\fP, no sorting is performed\&.
Note that \fBa\fP, \fBm\fP, and \fBc\fP compare
the age against the current time, hence the first name in the list is the
youngest file\&. Also note that the modifiers \fB^\fP and \fB\-\fP are used,
so `\fB*(^\-oL)\fP\&' gives a list of all files sorted by file size in descending
order, following any symbolic links\&.  Unless \fBoN\fP is used, multiple order
specifiers may occur to resolve ties\&.
\fBoe\fP and \fBo+\fP are special cases; they are each followed by shell code,
delimited as for the \fBe\fP glob qualifier and the \fB+\fP glob qualifier
respectively (see above)\&.  The code is executed for each matched file with
the parameter \fBREPLY\fP set to the name of the file on entry and
\fBglobsort\fP appended to \fBzsh_eval_context\fP\&.  The code
should modify the parameter \fBREPLY\fP in some fashion\&.  On return, the
value of the parameter is used instead of the file name as the string on
which to sort\&.  Unlike other sort operators, \fBoe\fP and \fBo+\fP may be
repeated, but note that the maximum number of sort operators of any kind
that may appear in any glob expression is 12\&.
like `\fBo\fP\&', but sorts in descending order; i\&.e\&. `\fB*(^oc)\fP' is the
same as `\fB*(Oc)\fP\&' and `\fB*(^Oc)\fP' is the same as `\fB*(oc)\fP'; `\fBOd\fP'
puts files in the current directory before those in subdirectories at each
level of the search\&.
specifies which of the matched filenames should be included in the
returned list\&. The syntax is the same as for array
subscripts\&. \fIbeg\fP and the optional \fIend\fP may be mathematical
expressions\&. As in parameter subscripting they may be negative to make 
them count from the last match backward\&. E\&.g\&.: `\fB*(\-OL[1,3])\fP\&'
gives a list of the names of the three largest files\&.
The \fIstring\fP will be prepended to each glob match as a separate
word\&.  \fIstring\fP is delimited in the same way as arguments to the
\fBe\fP glob qualifier described above\&.  The qualifier can be repeated;
the words are prepended separately so that the resulting command
line contains the words in the same order they were given in the
list of glob qualifiers\&.
A typical use for this is to prepend an option before all occurrences
of a file name; for example, the pattern `\fB*(P:\-f:)\fP\&' produces the
command line arguments `\fB\-f\fP \fIfile1\fP \fB\-f\fP \fIfile2\fP \&.\&.\&.\&'
More than one of these lists can be combined, separated by commas\&. The
whole list matches if at least one of the sublists matches (they are
`or\&'ed, the qualifiers in the sublists are `and'ed)\&.  Some qualifiers,
however, affect all matches generated, independent of the sublist in
which they are given\&.  These are the qualifiers `\fBM\fP\&', `\fBT\fP',
`\fBN\fP\&', `\fBD\fP', `\fBn\fP', `\fBo\fP', `\fBO\fP' and the subscripts given
in brackets (`\fB[\&.\&.\&.]\fP\&')\&.
If a `\fB:\fP\&' appears in a qualifier list, the remainder of the expression in
parenthesis is interpreted as a modifier (see the section `Modifiers\&'
in the section `History Expansion\&')\&.  Each modifier must be introduced by a
separate `\fB:\fP\&'\&.  Note also that the result after modification does not
have to be an existing file\&.  The name of any existing file can be followed
by a modifier of the form `\fB(:\&.\&.)\fP\&' even if no actual filename generation
is performed, although note that the presence of the parentheses
causes the entire expression to be subjected to any global pattern matching
options such as \fBNULL_GLOB\fP\&. Thus:
\fBls *(\-/)\fP
lists all directories and symbolic links that point to directories,
\fBls *(%W)\fP
lists all world\-writable device files in the current directory, and
\fBls *(W,X)\fP
lists all files in the current directory that are
world\-writable or world\-executable, and
\fBecho /tmp/foo*(u0^@:t)\fP
outputs the basename of all root\-owned files beginning with the string
`\fBfoo\fP\&' in \fB/tmp\fP, ignoring symlinks, and
\fBls *\&.*~(lex|parse)\&.[ch](^D^l1)\fP
lists all files having a link count of one whose names contain a dot
(but not those starting with a dot, since \fBGLOB_DOTS\fP is explicitly
switched off) except for \fBlex\&.c\fP, \fBlex\&.h\fP, \fBparse\&.c\fP and \fBparse\&.h\fP\&.
\fBprint b*\&.pro(#q:s/pro/shmo/)(#q\&.:s/builtin/shmiltin/)\fP
demonstrates how colon modifiers and other qualifiers may be chained
together\&.  The ordinary qualifier `\fB\&.\fP\&' is applied first, then the colon
modifiers in order from left to right\&.  So if \fBEXTENDED_GLOB\fP is set and
the base pattern matches the regular file \fBbuiltin\&.pro\fP, the shell will
print `\fBshmiltin\&.shmo\fP\&'\&.