-``` example
+```zsh
() {
print File $1:
cat $1
@@ -643,7 +633,7 @@ outputs something resembling the following
-``` example
+```zsh
File /tmp/zsh6nU0kS:
This be the verse
```
@@ -653,23 +643,23 @@ This be the verse
The temporary file created by the process substitution will be deleted
when the function exits.
------
+------------------------------------------------------------------------
-
-
+
## 14.3 Parameter Expansion
-
-
+
-The character ‘`$`’ is used to introduce parameter expansions. See
+The character ‘$’ is used to introduce parameter expansions. See
[Parameters](Parameters.html#Parameters) 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 `SH_WORD_SPLIT` is
+automatically split on whitespace unless the option SH_WORD_SPLIT is
set; see references to this option below for more details. This is an
important difference from other shells. However, as in other shells,
null words are elided from unquoted parameters’ expansions.
@@ -678,24 +668,24 @@ With default options, after the assignments:
-``` example
+```zsh
array=("first word" "" "third word")
scalar="only word"
```
-then `$array` substitutes two words, ‘`first word`’ and ‘`third word`’,
-and `$scalar` substitutes a single word ‘`only word`’. Note that second
-element of `array` was elided. Scalar parameters can be elided too if
-their value is null (empty). To avoid elision, use quoting as follows:
-`"$scalar"` for scalars and `"${array[@]}"` or `"${(@)array}"` for
-arrays. (The last two forms are equivalent.)
+then $array substitutes two words, ‘first word’ and ‘third word’, and
+$scalar substitutes a single word ‘only word’. Note that second element
+of array was elided. Scalar parameters can be elided too if their value
+is null (empty). To avoid elision, use quoting as follows: "$scalar" for
+scalars and "${array\[@\]}" or "${(@)array}" for arrays. (The last two
+forms are equivalent.)
-Parameter expansions can involve *flags*, as in ‘`${(@kv)aliases}`’, and
-other operators, such as ‘`${PREFIX:-"/usr/local"}`’. Parameter
-expansions can also be nested. These topics will be introduced below.
-The full rules are complicated and are noted at the end.
+Parameter expansions can involve *flags*, as in ‘${(@kv)aliases}’, and
+other operators, such as ‘${PREFIX:-"/usr/local"}’. Parameter expansions
+can also be nested. These topics will be introduced below. The full
+rules are complicated and are noted at the end.
In the expansions discussed below that require a pattern, the form of
the pattern is the same as that used for filename generation; see
@@ -705,1369 +695,1359 @@ subject to parameter expansion, command substitution, and arithmetic
expansion. In addition to the following operations, the colon modifiers
described in [Modifiers](#Modifiers) in [History
Expansion](#History-Expansion) can be applied: for example,
-`${i:s/foo/bar/}` performs string substitution on the expansion of
-parameter `$i`.
+${i:s/foo/bar/} performs string substitution on the expansion of
+parameter $i.
In the following descriptions, ‘`word`’ refers to a single word
substituted on the command line, not necessarily a space delimited word.
- - `${``name``}`
- The value, if any, of the parameter `name` 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
- `name`. In addition, more complicated forms of substitution usually
- require the braces to be present; exceptions, which only apply if
- the option `KSH_ARRAYS` is not set, are a single subscript or any
- colon modifiers appearing after the name, or any of the characters
- ‘`^`’, ‘`=`’, ‘`~`’, ‘`#`’ or ‘`+`’ appearing before the name, all
- of which work with or without braces.
-
- If `name` is an array parameter, and the `KSH_ARRAYS` option is not
- set, then the value of each element of `name` is substituted, one
- element per word. Otherwise, the expansion results in one word only;
- with `KSH_ARRAYS`, this is the first element of an array. No field
- splitting is done on the result unless the `SH_WORD_SPLIT` option is
- set. See also the flags `=` and `s:``string``:`.
+${`name`}
+The value, if any, of the parameter `name` 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 `name`. In addition,
+more complicated forms of substitution usually require the braces to be
+present; exceptions, which only apply if the option KSH_ARRAYS is not
+set, are a single subscript or any colon modifiers appearing after the
+name, or any of the characters ‘^’, ‘=’, ‘\~’, ‘#’ or ‘+’ appearing
+before the name, all of which work with or without braces.
- - `${+``name``}`
- If `name` is the name of a set parameter ‘`1`’ is substituted,
- otherwise ‘`0`’ is substituted.
+If `name` is an array parameter, and the KSH_ARRAYS option is not set,
+then the value of each element of `name` is substituted, one element per
+word. Otherwise, the expansion results in one word only; with
+KSH_ARRAYS, this is the first element of an array. No field splitting is
+done on the result unless the SH_WORD_SPLIT option is set. See also the
+flags = and s:`string`:.
- - `${``name``-``word``}`
- `${``name``:-``word``}`
- If `name` is set, or in the second form is non-null, then substitute
- its value; otherwise substitute `word`. In the second form `name`
- may be omitted, in which case `word` is always substituted.
+${+`name`}
+If `name` is the name of a set parameter ‘1’ is substituted, otherwise
+‘0’ is substituted.
- - `${``name``+``word``}`
- `${``name``:+``word``}`
- If `name` is set, or in the second form is non-null, then substitute
- `word`; otherwise substitute nothing.
+${`name`-`word`}
+${`name`:-`word`}
+If `name` is set, or in the second form is non-null, then substitute its
+value; otherwise substitute `word`. In the second form `name` may be
+omitted, in which case `word` is always substituted.
- - `${``name``=``word``}`
- `${``name``:=``word``}`
- `${``name``::=``word``}`
- In the first form, if `name` is unset then set it to `word`; in the
- second form, if `name` is unset or null then set it to `word`; and
- in the third form, unconditionally set `name` to `word`. In all
- forms, the value of the parameter is then substituted.
+${`name`+`word`}
+${`name`:+`word`}
+If `name` is set, or in the second form is non-null, then substitute
+`word`; otherwise substitute nothing.
- - `${``name``?``word``}`
- `${``name``:?``word``}`
- In the first form, if `name` is set, or in the second form if `name`
- is both set and non-null, then substitute its value; otherwise,
- print `word` and exit from the shell. Interactive shells instead
- return to the prompt. If `word` is omitted, then a standard message
- is printed.
+${`name`=`word`}
+${`name`:=`word`}
+${`name`::=`word`}
+In the first form, if `name` is unset then set it to `word`; in the
+second form, if `name` is unset or null then set it to `word`; and in
+the third form, unconditionally set `name` to `word`. In all forms, the
+value of the parameter is then substituted.
+
+${`name`?`word`}
+${`name`:?`word`}
+In the first form, if `name` is set, or in the second form if `name` is
+both set and non-null, then substitute its value; otherwise, print
+`word` and exit from the shell. Interactive shells instead return to the
+prompt. If `word` is omitted, then a standard message is printed.
In any of the above expressions that test a variable and substitute an
alternate `word`, note that you can use standard shell quoting in the
`word` value to selectively override the splitting done by the
-`SH_WORD_SPLIT` option and the `=` flag, but not splitting by the
-`s:``string``:` flag.
+SH_WORD_SPLIT option and the = flag, but not splitting by the
+s:`string`: flag.
In the following expressions, when `name` is an array and the
-substitution is not quoted, or if the ‘`(@)`’ flag or the `name``[@]`
+substitution is not quoted, or if the ‘(@)’ flag or the `name`\[@\]
syntax is used, matching and replacement is performed on each array
element separately.
- - `${``name``#``pattern``}`
- `${``name``##``pattern``}`
- If the `pattern` matches the beginning of the value of `name`, then
- substitute the value of `name` with the matched portion deleted;
- otherwise, just substitute the value of `name`. In the first form,
- the smallest matching pattern is preferred; in the second form, the
- largest matching pattern is preferred.
+${`name`#`pattern`}
+${`name`##`pattern`}
+If the `pattern` matches the beginning of the value of `name`, then
+substitute the value of `name` with the matched portion deleted;
+otherwise, just substitute the value of `name`. In the first form, the
+smallest matching pattern is preferred; in the second form, the largest
+matching pattern is preferred.
- - `${``name``%``pattern``}`
- `${``name``%%``pattern``}`
- If the `pattern` matches the end of the value of `name`, then
- substitute the value of `name` with the matched portion deleted;
- otherwise, just substitute the value of `name`. In the first form,
- the smallest matching pattern is preferred; in the second form, the
- largest matching pattern is preferred.
+${`name`%`pattern`}
+${`name`%%`pattern`}
+If the `pattern` matches the end of the value of `name`, then substitute
+the value of `name` with the matched portion deleted; otherwise, just
+substitute the value of `name`. In the first form, the smallest matching
+pattern is preferred; in the second form, the largest matching pattern
+is preferred.
- - `${``name``:#``pattern``}`
- If the `pattern` matches the value of `name`, then substitute the
- empty string; otherwise, just substitute the value of `name`. If
- `name` is an array the matching array elements are removed (use the
- ‘`(M)`’ flag to remove the non-matched elements).
+${`name`:#`pattern`}
+If the `pattern` matches the value of `name`, then substitute the empty
+string; otherwise, just substitute the value of `name`. If `name` is an
+array the matching array elements are removed (use the ‘(M)’ flag to
+remove the non-matched elements).
- - `${``name``:|``arrayname``}`
- If `arrayname` is the name (N.B., not contents) of an array
- variable, then any elements contained in `arrayname` are removed
- from the substitution of `name`. If the substitution is scalar,
- either because `name` is a scalar variable or the expression is
- quoted, the elements of `arrayname` are instead tested against the
- entire expression.
+${`name`:\|`arrayname`}
+If `arrayname` is the name (N.B., not contents) of an array variable,
+then any elements contained in `arrayname` are removed from the
+substitution of `name`. If the substitution is scalar, either because
+`name` is a scalar variable or the expression is quoted, the elements of
+`arrayname` are instead tested against the entire expression.
- - `${``name``:*``arrayname``}`
- Similar to the preceding substitution, but in the opposite sense, so
- that entries present in both the original substitution and as
- elements of `arrayname` are retained and others removed.
+${`name`:\*`arrayname`}
+Similar to the preceding substitution, but in the opposite sense, so
+that entries present in both the original substitution and as elements
+of `arrayname` are retained and others removed.
- - `${``name``:^``arrayname``}`
- `${``name``:^^``arrayname``}`
- Zips two arrays, such that the output array is twice as long as the
- shortest (longest for ‘`:^^`’) of `name` and `arrayname`, with the
- elements alternatingly being picked from them. For ‘`:^`’, if one of
- the input arrays is longer, the output will stop when the end of the
- shorter array is reached. Thus,
-
-
-
- ``` example
- a=(1 2 3 4); b=(a b); print ${a:^b}
- ```
-
-
-
- will output ‘`1 a 2 b`’. For ‘`:^^`’, then the input is repeated
- until all of the longer array has been used up and the above will
- output ‘`1 a 2 b 3 a 4 b`’.
-
- Either or both inputs may be a scalar, they will be treated as an
- array of length 1 with the scalar as the only element. If either
- array is empty, the other array is output with no extra elements
- inserted.
-
- Currently the following code will output ‘`a b`’ and ‘`1`’ as two
- separate elements, which can be unexpected. The second print
- provides a workaround which should continue to work if this is
- changed.
-
-
-
- ``` example
- a=(a b); b=(1 2); print -l "${a:^b}"; print -l "${${a:^b}}"
- ```
-
-
+${`name`:^`arrayname`}
+${`name`:^^`arrayname`}
+Zips two arrays, such that the output array is twice as long as the
+shortest (longest for ‘:^^’) of name and arrayname, with the elements
+alternatingly being picked from them. For ‘:^’, if one of the input
+arrays is longer, the output will stop when the end of the shorter array
+is reached. Thus,
- - `${``name``:``offset``}`
- `${``name``:``offset``:``length``}`
- This syntax gives effects similar to parameter subscripting in the
- form `$``name``[``start``,``end``]`, but is compatible with other
- shells; note that both `offset` and `length` are interpreted
- differently from the components of a subscript.
-
- If `offset` is non-negative, then if the variable `name` is a scalar
- substitute the contents starting `offset` characters from the first
- character of the string, and if `name` is an array substitute
- elements starting `offset` elements from the first element. If
- `length` is given, substitute that many characters or elements,
- otherwise the entire rest of the scalar or array.
-
- A positive `offset` is always treated as the offset of a character
- or element in `name` 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 `KSH_ARRAYS`.
-
- 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.
-
- When positive, `length` counts from the `offset` position toward the
- end of the scalar or array. When negative, `length` counts back from
- the end. If this results in a position smaller than `offset`, a
- diagnostic is printed and nothing is substituted.
-
- The option `MULTIBYTE` is obeyed, i.e. the offset and length count
- multibyte characters where appropriate.
-
- `offset` and `length` undergo the same set of shell substitutions as
- for scalar assignment; in addition, they are then subject to
- arithmetic evaluation. Hence, for example
-
-
-
- ``` example
- print ${foo:3}
- print ${foo: 1 + 2}
- print ${foo:$(( 1 + 2))}
- print ${foo:$(echo 1 + 2)}
- ```
-
-
-
- all have the same effect, extracting the string starting at the
- fourth character of `$foo` if the substitution would otherwise
- return a scalar, or the array starting at the fourth element if
- `$foo` would return an array. Note that with the option `KSH_ARRAYS`
- `$foo` always returns a scalar (regardless of the use of the offset
- syntax) and a form such as `${foo[*]:3}` is required to extract
- elements of an array named `foo`.
-
- If `offset` is negative, the `-` may not appear immediately after
- the `:` as this indicates the `${``name``:-``word``}` form of
- substitution. Instead, a space may be inserted before the `-`.
- Furthermore, neither `offset` nor `length` may begin with an
- alphabetic character or `&` as these are used to indicate
- history-style modifiers. To substitute a value from a variable, the
- recommended approach is to precede it with a `$` as this signifies
- the intention (parameter substitution can easily be rendered
- unreadable); however, as arithmetic substitution is performed, the
- expression `${var: offs}` does work, retrieving the offset from
- `$offs`.
-
- For further compatibility with other shells there is a special case
- for array offset 0. This usually accesses the first element of the
- array. However, if the substitution refers to the positional
- parameter array, e.g. `$@` or `$*`, then offset 0 instead refers to
- `$0`, offset 1 refers to `$1`, and so on. In other words, the
- positional parameter array is effectively extended by prepending
- `$0`. Hence `${*:0:1}` substitutes `$0` and `${*:1:1}` substitutes
- `$1`.
+
- - `${``name``/``pattern``/``repl``}`
- `${``name``//``pattern``/``repl``}`
- `${``name``:/``pattern``/``repl``}`
- Replace the longest possible match of `pattern` in the expansion of
- parameter `name` by string `repl`. The first form replaces just the
- first occurrence, the second form all occurrences, and the third
- form replaces only if `pattern` matches the entire string. Both
- `pattern` and `repl` are subject to double-quoted substitution, so
- that expressions like `${name/$opat/$npat}` will work, but obey the
- usual rule that pattern characters in `$opat` are not treated
- specially unless either the option `GLOB_SUBST` is set, or `$opat`
- is instead substituted as `${~opat}`.
-
- The `pattern` may begin with a ‘`#`’, in which case the `pattern`
- must match at the start of the string, or ‘`%`’, in which case it
- must match at the end of the string, or ‘`#%`’ in which case the
- `pattern` must match the entire string. The `repl` may be an empty
- string, in which case the final ‘`/`’ may also be omitted. To quote
- the final ‘`/`’ in other cases it should be preceded by a single
- backslash; this is not necessary if the ‘`/`’ occurs inside a
- substituted parameter. Note also that the ‘`#`’, ‘`%`’ and ‘`#%` are
- not active if they occur inside a substituted parameter, even at the
- start.
-
- If, after quoting rules apply, `${``name``}` expands to an array,
- the replacements act on each element individually. Note also the
- effect of the `I` and `S` parameter expansion flags below; however,
- the flags `M`, `R`, `B`, `E` and `N` are not useful.
-
- For example,
-
-
-
- ``` example
- foo="twinkle twinkle little star" sub="t*e" rep="spy"
- print ${foo//${~sub}/$rep}
- print ${(S)foo//${~sub}/$rep}
- ```
-
-
-
- Here, the ‘`~`’ ensures that the text of `$sub` is treated as a
- pattern rather than a plain string. In the first case, the longest
- match for `t*e` is substituted and the result is ‘`spy star`’, while
- in the second case, the shortest matches are taken and the result is
- ‘`spy spy lispy star`’.
+```zsh
+a=(1 2 3 4); b=(a b); print ${a:^b}
+```
- - `${#``spec``}`
- If `spec` is one of the above substitutions, substitute the length
- in characters of the result instead of the result itself. If `spec`
- is an array expression, substitute the number of elements of the
- result. This has the side-effect that joining is skipped even in
- quoted forms, which may affect other sub-expressions in `spec`. Note
- that ‘`^`’, ‘`=`’, and ‘`~`’, below, must appear to the left of
- ‘`#`’ when these forms are combined.
-
- If the option `POSIX_IDENTIFIERS` is not set, and `spec` is a simple
- name, then the braces are optional; this is true even for special
- parameters so e.g. `$#-` and `$#*` take the length of the string
- `$-` and the array `$*` respectively. If `POSIX_IDENTIFIERS` is set,
- then braces are required for the `#` to be treated in this fashion.
+
- - `${^``spec``}`
-
-
-
-
- Turn on the `RC_EXPAND_PARAM` option for the evaluation of `spec`;
- if the ‘`^`’ is doubled, turn it off. When this option is set, array
- expansions of the form `foo``${``xx``}``bar`, where the parameter
- `xx` is set to `(``a b c``)`, are substituted with ‘`fooabar foobbar
- foocbar`’ instead of the default ‘`fooa b cbar`’. 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., `${^var}` becomes
- `{$var[1],$var[2],`...`}`, and is processed as described in [Brace
- Expansion](#Brace-Expansion) below: note, however, the expansion
- happens immediately, with any explicit brace expansion happening
- later. If word splitting is also in effect the `$var[``N``]` may
- themselves be split into different list elements.
+will output ‘1 a 2 b’. For ‘:^^’, then the input is repeated until all
+of the longer array has been used up and the above will output ‘1 a 2 b
+3 a 4 b’.
- - `${=``spec``}`
-
-
-
-
- Perform word splitting using the rules for `SH_WORD_SPLIT` during
- the evaluation of `spec`, but regardless of whether the parameter
- appears in double quotes; if the ‘`=`’ is doubled, turn it off.
-
This forces parameter
- expansions to be split into separate words before substitution,
- using `IFS` as a delimiter. This is done by default in most other
- shells.
-
- Note that splitting is applied to `word` in the assignment forms of
- `spec` *before* the assignment to `name` is performed. This affects
- the result of array assignments with the `A` flag.
+Either or both inputs may be a scalar, they will be treated as an array
+of length 1 with the scalar as the only element. If either array is
+empty, the other array is output with no extra elements inserted.
- - `${~``spec``}`
-
-
- Turn on the `GLOB_SUBST` option for the evaluation of `spec`; if the
- ‘`~`’ 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 ‘`=`’ and ‘`!=`’ operators in conditions.
-
- In nested substitutions, note that the effect of the `~` 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 `foo` is set to `*`, `${~foo//\*/*.c}` is
- substituted by the pattern `*.c`, which may be expanded by filename
- generation, but `${${~foo}//\*/*.c}` substitutes to the string
- `*.c`, which will not be further expanded.
+Currently the following code will output ‘a b’ and ‘1’ as two separate
+elements, which can be unexpected. The second print provides a
+workaround which should continue to work if this is changed.
-If a `${`...`}` type parameter expression or a `$(`...`)` type command
+
+
+```zsh
+a=(a b); b=(1 2); print -l "${a:^b}"; print -l "${${a:^b}}"
+```
+
+
+
+${`name`:`offset`}
+${`name`:`offset`:`length`}
+This syntax gives effects similar to parameter subscripting in the form
+$`name`\[`start`,`end`\], but is compatible with other shells; note that
+both `offset` and `length` are interpreted differently from the
+components of a subscript.
+
+If `offset` is non-negative, then if the variable `name` is a scalar
+substitute the contents starting `offset` characters from the first
+character of the string, and if `name` is an array substitute elements
+starting `offset` elements from the first element. If `length` is given,
+substitute that many characters or elements, otherwise the entire rest
+of the scalar or array.
+
+A positive `offset` is always treated as the offset of a character or
+element in `name` 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
+KSH_ARRAYS.
+
+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.
+
+When positive, `length` counts from the `offset` position toward the end
+of the scalar or array. When negative, `length` counts back from the
+end. If this results in a position smaller than `offset`, a diagnostic
+is printed and nothing is substituted.
+
+The option MULTIBYTE is obeyed, i.e. the offset and length count
+multibyte characters where appropriate.
+
+`offset` and `length` undergo the same set of shell substitutions as for
+scalar assignment; in addition, they are then subject to arithmetic
+evaluation. Hence, for example
+
+
+
+```zsh
+print ${foo:3}
+print ${foo: 1 + 2}
+print ${foo:$(( 1 + 2))}
+print ${foo:$(echo 1 + 2)}
+```
+
+
+
+all have the same effect, extracting the string starting at the fourth
+character of $foo if the substitution would otherwise return a scalar,
+or the array starting at the fourth element if $foo would return an
+array. Note that with the option KSH_ARRAYS $foo always returns a scalar
+(regardless of the use of the offset syntax) and a form such as
+${foo\[\*\]:3} is required to extract elements of an array named foo.
+
+If `offset` is negative, the - may not appear immediately after the : as
+this indicates the ${`name`:-`word`} form of substitution. Instead, a
+space may be inserted before the -. Furthermore, neither `offset` nor
+`length` may begin with an alphabetic character or & as these are used
+to indicate history-style modifiers. To substitute a value from a
+variable, the recommended approach is to precede it with a $ as this
+signifies the intention (parameter substitution can easily be rendered
+unreadable); however, as arithmetic substitution is performed, the
+expression ${var: offs} does work, retrieving the offset from $offs.
+
+For further compatibility with other shells there is a special case for
+array offset 0. This usually accesses the first element of the array.
+However, if the substitution refers to the positional parameter array,
+e.g. $@ or $\*, then offset 0 instead refers to $0, offset 1 refers to
+$1, and so on. In other words, the positional parameter array is
+effectively extended by prepending $0. Hence ${\*:0:1} substitutes $0
+and ${\*:1:1} substitutes $1.
+
+${`name`/`pattern`/`repl`}
+${`name`//`pattern`/`repl`}
+${`name`:/`pattern`/`repl`}
+Replace the longest possible match of `pattern` in the expansion of
+parameter `name` by string `repl`. The first form replaces just the
+first occurrence, the second form all occurrences, and the third form
+replaces only if `pattern` matches the entire string. Both `pattern` and
+`repl` are subject to double-quoted substitution, so that expressions
+like ${name/$opat/$npat} will work, but obey the usual rule that pattern
+characters in $opat are not treated specially unless either the option
+GLOB_SUBST is set, or $opat is instead substituted as ${\~opat}.
+
+The `pattern` may begin with a ‘#’, in which case the `pattern` must
+match at the start of the string, or ‘%’, in which case it must match at
+the end of the string, or ‘#%’ in which case the `pattern` must match
+the entire string. The `repl` may be an empty string, in which case the
+final ‘/’ may also be omitted. To quote the final ‘/’ in other cases it
+should be preceded by a single backslash; this is not necessary if the
+‘/’ occurs inside a substituted parameter. Note also that the ‘#’, ‘%’
+and ‘#% are not active if they occur inside a substituted parameter,
+even at the start.
+
+If, after quoting rules apply, ${`name`} expands to an array, the
+replacements act on each element individually. Note also the effect of
+the I and S parameter expansion flags below; however, the flags M, R, B,
+E and N are not useful.
+
+For example,
+
+
+
+```zsh
+foo="twinkle twinkle little star" sub="t*e" rep="spy"
+print ${foo//${~sub}/$rep}
+print ${(S)foo//${~sub}/$rep}
+```
+
+
+
+Here, the ‘\~’ ensures that the text of $sub is treated as a pattern
+rather than a plain string. In the first case, the longest match for
+t\*e is substituted and the result is ‘spy star’, while in the second
+case, the shortest matches are taken and the result is ‘spy spy lispy
+star’.
+
+${#`spec`}
+If `spec` is one of the above substitutions, substitute the length in
+characters of the result instead of the result itself. If `spec` is an
+array expression, substitute the number of elements of the result. This
+has the side-effect that joining is skipped even in quoted forms, which
+may affect other sub-expressions in `spec`. Note that ‘^’, ‘=’, and
+‘\~’, below, must appear to the left of ‘#’ when these forms are
+combined.
+
+If the option POSIX_IDENTIFIERS is not set, and `spec` is a simple name,
+then the braces are optional; this is true even for special parameters
+so e.g. $#- and $#\* take the length of the string $- and the array $\*
+respectively. If POSIX_IDENTIFIERS is set, then braces are required for
+the # to be treated in this fashion.
+
+${^`spec`}
+${^^`spec`}
+
+
+Turn on the RC_EXPAND_PARAM option for the evaluation of `spec`; if the
+‘^’ is doubled, turn it off. When this option is set, array expansions
+of the form `foo`${`xx`}`bar`, where the parameter `xx` is set to
+(`a b c`), are substituted with ‘`fooabar foobbar foocbar`’ instead of
+the default ‘`fooa b cbar`’. 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., ${^var} becomes {$var\[1\],$var\[2\],...},
+and is processed as described in [Brace Expansion](#Brace-Expansion)
+below: note, however, the expansion happens immediately, with any
+explicit brace expansion happening later. If word splitting is also in
+effect the $var\[`N`\] may themselves be split into different list
+elements.
+
+${=`spec`}
+${==`spec`}
+
+
+Perform word splitting using the rules for SH_WORD_SPLIT during the
+evaluation of `spec`, but regardless of whether the parameter appears in
+double quotes; if the ‘=’ is doubled, turn it off.
This forces parameter expansions to
+be split into separate words before substitution, using IFS as a
+delimiter. This is done by default in most other shells.
+
+Note that splitting is applied to `word` in the assignment forms of
+`spec` *before* the assignment to `name` is performed. This affects the
+result of array assignments with the A flag.
+
+${\~`spec`}
+${\~\~`spec`}
+
+
+Turn on the GLOB_SUBST option for the evaluation of `spec`; if the ‘\~’
+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 ‘=’ and ‘!=’
+operators in conditions.
+
+In nested substitutions, note that the effect of the \~ 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 foo is set to \*, ${\~foo//\\\*/\*.c} is substituted by the
+pattern \*.c, which may be expanded by filename generation, but
+${${\~foo}//\\\*/\*.c} substitutes to the string \*.c, which will not be
+further expanded.
+
+If a ${...} type parameter expression or a $(...) type command
substitution is used in place of `name` above, it is expanded first and
the result is used as if it were the value of `name`. Thus it is
-possible to perform nested operations: `${${foo#head}%tail}` substitutes
-the value of `$foo` with both ‘`head`’ and ‘`tail`’ deleted. The form
-with `$(`...`)` is often useful in combination with the flags described
-next; see the examples below. Each `name` or nested `${`...`}` in a
-parameter expansion may also be followed by a subscript expression as
-described in [Array Parameters](Parameters.html#Array-Parameters).
+possible to perform nested operations: ${${foo#head}%tail} substitutes
+the value of $foo with both ‘head’ and ‘tail’ deleted. The form with
+$(...) is often useful in combination with the flags described next; see
+the examples below. Each `name` or nested ${...} in a parameter
+expansion may also be followed by a subscript expression as described in
+[Array Parameters](Parameters.html#Array-Parameters).
Note that double quotes may appear around nested expressions, in which
case only the part inside is treated as quoted; for example,
-`${(f)"$(foo)"}` quotes the result of `$(foo)`, but the flag ‘`(f)`’
-(see below) is applied using the rules for unquoted expansions. Note
-further that quotes are themselves nested in this context; for example,
-in `"${(@f)"$(foo)"}"`, there are two sets of quotes, one surrounding
-the whole expression, the other (redundant) surrounding the `$(foo)` as
+${(f)"$(foo)"} quotes the result of $(foo), but the flag ‘(f)’ (see
+below) is applied using the rules for unquoted expansions. Note further
+that quotes are themselves nested in this context; for example, in
+"${(@f)"$(foo)"}", there are two sets of quotes, one surrounding the
+whole expression, the other (redundant) surrounding the $(foo) as
before.
------
+------------------------------------------------------------------------
### 14.3.1 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, ‘(`q%q%q`)’ means the same thing
-as the more readable ‘(`%%qqq`)’. The following flags are supported:
+need not be consecutive; for example, ‘(q%q%q)’ means the same thing as
+the more readable ‘(%%qqq)’. The following flags are supported:
- - `#`
- 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 `#` without parentheses.
-
- If the `MULTIBYTE` option is set and the number is greater than 127
- (i.e. not an ASCII character) it is treated as a Unicode character.
+#
+Evaluate the resulting words as numeric expressions and interpret these
+as character codes. Output the corresponding characters. Note that this
+form is entirely distinct from use of the # without parentheses.
- - `%`
- Expand all `%` escapes in the resulting words in the same way as in
- prompts (see [Prompt
- Expansion](Prompt-Expansion.html#Prompt-Expansion)). If this flag is
- given twice, full prompt expansion is done on the resulting words,
- depending on the setting of the `PROMPT_PERCENT`, `PROMPT_SUBST` and
- `PROMPT_BANG` options.
+If the MULTIBYTE option is set and the number is greater than 127 (i.e.
+not an ASCII character) it is treated as a Unicode character.
- - `@`
- In double quotes, array elements are put into separate words. E.g.,
- ‘`"${(@)foo}"`’ is equivalent to ‘`"${foo[@]}"`’ and
- ‘`"${(@)foo[1,2]}"`’ is the same as ‘`"$foo[1]" "$foo[2]"`’. This
- is distinct from *field splitting* by the `f`, `s` or `z` flags,
- which still applies within each array element.
+%
+Expand all % escapes in the resulting words in the same way as in
+prompts (see [Prompt
+Expansion](Prompt-Expansion.html#Prompt-Expansion)). If this flag is
+given twice, full prompt expansion is done on the resulting words,
+depending on the setting of the PROMPT_PERCENT, PROMPT_SUBST and
+PROMPT_BANG options.
- - `A`
- Convert the substitution into an array expression, even if it
- otherwise would be scalar. This has lower precedence than
- subscripting, so one level of nested expansion is required in order
- that subscripts apply to array elements. Thus
- `${${(A``)``name``}[1]}` yields the full value of `name` when `name`
- is scalar.
-
- This assigns an array parameter with ‘`${`...`=`...`}`’,
- ‘`${`...`:=`...`}`’ or ‘`${`...`::=`...`}`’. If this flag is
- repeated (as in ‘`AA`’), assigns an associative array parameter.
- Assignment is made before sorting or padding; if field splitting is
- active, the `word` part is split before assignment. The `name` part
- may be a subscripted range for ordinary arrays; when assigning an
- associative array, the `word` part *must* be converted to an array,
- for example by using ‘`${(AA)=``name``=`...`}`’ to activate field
- splitting.
-
- Surrounding context such as additional nesting or use of the value
- in a scalar assignment may cause the array to be joined back into a
- single string again.
+@
+In double quotes, array elements are put into separate words. E.g.,
+‘"${(@)foo}"’ is equivalent to ‘"${foo\[@\]}"’ and ‘"${(@)foo\[1,2\]}"’
+is the same as ‘"$foo\[1\]" "$foo\[2\]"’. This is distinct from *field
+splitting* by the f, s or z flags, which still applies within each array
+element.
- - `a`
- Sort in array index order; when combined with ‘`O`’ sort in reverse
- array index order. Note that ‘`a`’ is therefore equivalent to the
- default but ‘`Oa`’ is useful for obtaining an array’s elements in
- reverse order.
+A
+Convert the substitution into an array expression, even if it otherwise
+would be scalar. This has lower precedence than subscripting, so one
+level of nested expansion is required in order that subscripts apply to
+array elements. Thus ${${(A)`name`}\[1\]} yields the full value of
+`name` when `name` is scalar.
- - `b`
- Quote with backslashes only characters that are special to pattern
- matching. This is useful when the contents of the variable are to be
- tested using `GLOB_SUBST`, including the `${~``...``}` switch.
-
- Quoting using one of the `q` family of flags does not work for this
- purpose since quotes are not stripped from non-pattern characters by
- `GLOB_SUBST`. In other words,
-
-
-
- ``` example
- pattern=${(q)str}
- [[ $str = ${~pattern} ]]
- ```
-
-
-
- works if `$str` is ‘`a*b`’ but not if it is ‘`a b`’, whereas
-
-
-
- ``` example
- pattern=${(b)str}
- [[ $str = ${~pattern} ]]
- ```
-
-
-
- is always true for any possible value of `$str`.
+This assigns an array parameter with ‘${...=...}’, ‘${...:=...}’ or
+‘${...::=...}’. If this flag is repeated (as in ‘AA’), assigns an
+associative array parameter. Assignment is made before sorting or
+padding; if field splitting is active, the `word` part is split before
+assignment. The `name` part may be a subscripted range for ordinary
+arrays; when assigning an associative array, the `word` part *must* be
+converted to an array, for example by using ‘${(AA)=`name`=...}’ to
+activate field splitting.
- - `c`
- With `${#``name``}`, count the total number of characters in an
- array, as if the elements were concatenated with spaces between
- them. This is not a true join of the array, so other expressions
- used with this flag may have an effect on the elements of the array
- before it is counted.
+Surrounding context such as additional nesting or use of the value in a
+scalar assignment may cause the array to be joined back into a single
+string again.
- - `C`
- Capitalize the resulting words. ‘Words’ in this case refers to
- sequences of alphanumeric characters separated by non-alphanumerics,
- *not* to words that result from field splitting.
+a
+Sort in array index order; when combined with ‘O’ sort in reverse array
+index order. Note that ‘a’ is therefore equivalent to the default but
+‘Oa’ is useful for obtaining an array’s elements in reverse order.
- - `D`
- 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 substituted)
- is then quoted so that the whole string can be used as a shell
- argument. This is the reverse of ‘`~`’ substitution: see [Filename
- Expansion](#Filename-Expansion).
+b
+Quote with backslashes only characters that are special to pattern
+matching. This is useful when the contents of the variable are to be
+tested using GLOB_SUBST, including the ${\~`...`} switch.
- - `e`
- Perform single word shell expansions, namely *parameter expansion*,
- *command substitution* and *arithmetic expansion*, on the result.
- Such expansions can be nested but too deep recursion may have
+Quoting using one of the q family of flags does not work for this
+purpose since quotes are not stripped from non-pattern characters by
+GLOB_SUBST. In other words,
- - `f`
- Split the result of the expansion at newlines. This is a shorthand
- for ‘`ps:\n:`’.
+
- - `F`
- Join the words of arrays together using newline as a separator. This
- is a shorthand for ‘`pj:\n:`’.
+```zsh
+pattern=${(q)str}
+[[ $str = ${~pattern} ]]
+```
- - `g:``opts``:`
- Process escape sequences like the echo builtin when no options are
- given (`g::`). With the `o` option, octal escapes don’t take a
- leading zero. With the `c` option, sequences like ‘`^X`’ are also
- processed. With the `e` option, processes ‘`\M-t`’ and similar
- sequences like the print builtin. With both of the `o` and `e`
- options, behaves like the print builtin except that in none of these
- modes is ‘`\c`’ interpreted.
+
- - `i`
- Sort case-insensitively. May be combined with ‘`n`’ or ‘`O`’.
+works if $str is ‘a\*b’ but not if it is ‘a b’, whereas
- - `k`
- If `name` refers to an associative array, substitute the *keys*
- (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. With the
- `KSH_ARRAYS` option a subscript ‘`[*]`’ or ‘`[@]`’ is needed to
- operate on the whole array, as usual.
+
- - `L`
- Convert all letters in the result to lower case.
+```zsh
+pattern=${(b)str}
+[[ $str = ${~pattern} ]]
+```
- - `n`
- 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 ‘`foo1 foo02 foo2 foo3 foo20 foo23`’ is sorted into
- the order shown. May be combined with ‘`i`’ or ‘`O`’.
+
- - `o`
- 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 ‘`a`’, ‘`i`’ or ‘`n`’.
+is always true for any possible value of $str.
- - `O`
- Sort the resulting words in descending order; ‘`O`’ without ‘`a`’,
- ‘`i`’ or ‘`n`’ sorts in reverse lexical order. May be combined
- with ‘`a`’, ‘`i`’ or ‘`n`’ to reverse the order of sorting.
+c
+With ${#`name`}, count the total number of characters in an array, as if
+the elements were concatenated with spaces between them. This is not a
+true join of the array, so other expressions used with this flag may
+have an effect on the elements of the array before it is counted.
- - `P`
- This forces the value of the parameter `name` to be interpreted as a
- further parameter name, whose value will be used where appropriate.
- Note that flags set with one of the `typeset` family of commands (in
- particular case transformations) are not applied to the value of
- `name` 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 ‘`foo=bar`’ and ‘`bar=baz`’, the strings
- `${(P)foo}`, `${(P)${foo}}`, and `${(P)$(echo bar)}` will be
- expanded to ‘`baz`’.
-
- Likewise, if the reference is itself nested, the expression with the
- flag is treated as if it were directly replaced by the parameter
- name. It is an error if this nested substitution produces an array
- with more than one word. For example, if ‘`name=assoc`’ where the
- parameter `assoc` is an associative array, then
- ‘`${${(P)name}[elt]}`’ refers to the element of the associative
- subscripted ‘`elt`’.
+C
+Capitalize the resulting words. ‘Words’ in this case refers to sequences
+of alphanumeric characters separated by non-alphanumerics, *not* to
+words that result from field splitting.
- - `q`
- Quote characters that are special to the shell in the resulting
- words with `$’\``NNN``’` 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 characters is attempted. If the flag is given four times,
- the words are quoted in single quotes preceded by a `$`. 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 `q-` is given (only a single `q` 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 output.
-
- If a `q+` is given, an extended form of minimal quoting is used that
- This quoting is similar to that used by the output of values by the
- `typeset` family of commands.
+D
+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 substituted) is then quoted
+so that the whole string can be used as a shell argument. This is the
+reverse of ‘\~’ substitution: see [Filename
+Expansion](#Filename-Expansion).
- - `Q`
- Remove one level of quotes from the resulting words.
+e
+Perform single word shell expansions, namely *parameter expansion*,
+*command substitution* and *arithmetic expansion*, on the result. Such
+expansions can be nested but too deep recursion may have
- - `t`
- 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 (‘`-`’). The first keyword in the string
- describes the main type, it can be one of ‘`scalar`’, ‘`array`’,
- ‘`integer`’, ‘`float`’ or ‘`association`’. The other keywords
- describe the type in more detail:
-
- - `local`
- for local parameters
-
- - `left`
- for left justified parameters
-
- - `right_blanks`
- for right justified parameters with leading blanks
-
- - `right_zeros`
- for right justified parameters with leading zeros
-
- - `lower`
- for parameters whose value is converted to all lower case when
- it is expanded
-
- - `upper`
- for parameters whose value is converted to all upper case when
- it is expanded
-
- - `readonly`
- for readonly parameters
-
- - `tag`
- for tagged parameters
-
- - `export`
- for exported parameters
-
- - `unique`
- for arrays which keep only the first occurrence of duplicated
- values
-
- - `hide`
- for parameters with the ‘hide’ flag
-
- - `hideval`
- for parameters with the ‘hideval’ flag
-
- - `special`
- for special parameters defined by the shell
+f
+Split the result of the expansion at newlines. This is a shorthand for
+‘ps:\\n:’.
- - `u`
- Expand only the first occurrence of each unique word.
+F
+Join the words of arrays together using newline as a separator. This is
+a shorthand for ‘pj:\\n:’.
- - `U`
- Convert all letters in the result to upper case.
+g:`opts`:
+Process escape sequences like the echo builtin when no options are given
+(g::). With the o option, octal escapes don’t take a leading zero. With
+the c option, sequences like ‘^X’ are also processed. With the e option,
+processes ‘\\M-t’ and similar sequences like the print builtin. With
+both of the o and e options, behaves like the print builtin except that
+in none of these modes is ‘\\c’ interpreted.
- - `v`
- Used with `k`, 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.
+i
+Sort case-insensitively. May be combined with ‘n’ or ‘O’.
- - `V`
- Make any special characters in the resulting words visible.
+k
+If `name` refers to an associative array, substitute the *keys* (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. With the KSH_ARRAYS option a
+subscript ‘\[\*\]’ or ‘\[@\]’ is needed to operate on the whole array,
+as usual.
- - `w`
- With `${#``name``}`, count words in arrays or strings; the `s` flag
- may be used to set a word delimiter.
+L
+Convert all letters in the result to lower case.
- - `W`
- Similar to `w` with the difference that empty words between repeated
- delimiters are also counted.
+n
+Sort decimal integers numerically; if the first differing characters of
+two test strings are not digits, sorting is lexical. ‘+’ and ‘-’ are not
+treated specially; they are treated as any other non-digit. Integers
+with more initial zeroes are sorted before those with fewer or none.
+Hence the array ‘foo+24 foo1 foo02 foo2 foo3 foo20 foo23’ is sorted into
+the order shown. May be combined with ‘i’ or ‘O’.
- - `X`
- With this flag, parsing errors occurring with the `Q`, `e` and `#`
- flags or the pattern matching forms such as
- ‘`${``name``#``pattern``}`’ are reported. Without the flag, errors
- are silently ignored.
+\-
+As n, but a leading minus sign indicates a negative decimal integer. A
+leading minus sign not followed by an integer does not trigger numeric
+sorting. Note that ‘+’ signs are not handled specially (this may change
+in the future).
- - `z`
- 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 `INTERACTIVE_COMMENTS` option unset
- (however, see the `Z` flag below for related options)
-
- Note that this is done very late, even later than the ‘`(s)`’ flag.
- So to access single words in the result use nested expansions as in
- ‘`${${(z)foo}[2]}`’. Likewise, to remove the quotes in the
- resulting words use ‘`${(Q)${(z)foo}}`’.
+o
+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 ‘a’, ‘i’, ‘n’ or
+‘-’.
- - `0`
- Split the result of the expansion on null bytes. This is a shorthand
- for ‘`ps:\0:`’.
+O
+Sort the resulting words in descending order; ‘O’ without ‘a’, ‘i’, ‘n’
+or ‘-’ sorts in reverse lexical order. May be combined with ‘a’, ‘i’,
+‘n’ or ‘-’ to reverse the order of sorting.
-The following flags (except `p`) are followed by one or more arguments
-as shown. Any character, or the matching pairs ‘`(`...`)`’, ‘`{`...`}`’,
-‘`[`...`]`’, or ‘`<`...`>`’, 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.
+P
+This forces the value of the parameter `name` to be interpreted as a
+further parameter name, whose value will be used where appropriate. Note
+that flags set with one of the typeset family of commands (in particular
+case transformations) are not applied to the value of `name` used in
+this fashion.
- - `p`
- Recognize the same escape sequences as the `print` builtin in string
- arguments to any of the flags described below that follow this
- argument.
-
- Alternatively, with this option string arguments may be in the form
- `$``var` in which case the value of the variable is substituted.
- Note this form is strict; the string argument does not undergo
- general parameter expansion.
-
- For example,
-
-
-
- ``` example
- sep=:
- val=a:b:c
- print ${(ps.$sep.)val}
- ```
-
-
-
- splits the variable on a `:`.
+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 ‘foo=bar’ and ‘bar=baz’, the strings ${(P)foo}, ${(P)${foo}},
+and ${(P)$(echo bar)} will be expanded to ‘baz’.
- - `~`
- Strings inserted into the expansion by any of the flags below are to
- be treated as patterns. This applies to the string arguments of
- flags that follow `~` within the same set of parentheses. Compare
- with `~` outside parentheses, which forces the entire substituted
- string to be treated as a pattern. Hence, for example,
-
-
-
- ``` example
- [[ "?" = ${(~j.|.)array} ]]
- ```
-
-
-
- treats ‘`|`’ as a pattern and succeeds if and only if `$array`
- contains the string ‘`?`’ as an element. The `~` may be repeated to
- toggle the behaviour; its effect only lasts to the end of the
- parenthesised group.
+Likewise, if the reference is itself nested, the expression with the
+flag is treated as if it were directly replaced by the parameter name.
+It is an error if this nested substitution produces an array with more
+than one word. For example, if ‘name=assoc’ where the parameter assoc is
+an associative array, then ‘${${(P)name}\[elt\]}’ refers to the element
+of the associative subscripted ‘elt’.
- - `j:``string``:`
- Join the words of arrays together using `string` as a separator.
-
Note that
- this occurs before field splitting by the `s:``string``:` flag or
- the `SH_WORD_SPLIT` option.
+q
+Quote characters that are special to the shell in the resulting words
+with $’\\`NNN`’ form, with separate quotes for each octet.
- - `l:``expr``::``string1``::``string2``:`
- Pad the resulting words on the left. Each word will be truncated if
- required and placed in a field `expr` characters wide.
-
- The arguments `:``string1``:` and `:``string2``:` 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 `string1` (concatenated as
- often as needed) or spaces if `string1` is not given. If both
- `string1` and `string2` are given, `string2` is inserted once
- directly to the left of each word, truncated if necessary, before
- `string1` is used to produce any remaining padding.
-
- If either of `string1` or `string2` is present but empty, i.e. there
- are two delimiters together at that point, the first character of
- `$IFS` is used instead.
-
- If the `MULTIBYTE` option is in effect, the flag `m` 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 `MULTIBYTE` 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.
+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
+characters is attempted. If the flag is given four times, the words are
+quoted in single quotes preceded by a $. 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.
- - `m`
- Only useful together with one of the flags `l` or `r` or with the
- `#` length operator when the `MULTIBYTE` option is in effect. Use
- the character width reported by the system in calculating how much
- of the string it occupies or the overall unit, however certain Asian
- character sets and certain special effects use wider characters;
- combining characters have zero width. would actually be displayed
- will vary.
-
- If the `m` is repeated, the character either counts zero (if it has
- 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).
+If a q- is given (only a single q 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 output.
- - `r:``expr``::``string1``::``string2``:`
- As `l`, but pad the words on the right and insert `string2`
- 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.
+If a q+ is given, an extended form of minimal quoting is used that This
+quoting is similar to that used by the output of values by the typeset
+family of commands.
- - `s:``string``:`
- Force field splitting at the separator `string`. Note that a
- `string` 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 `IFS` parameter. See also the `=` flag and the
- `SH_WORD_SPLIT` option. An empty string may also be given in which
- case every character will be a separate element.
-
- 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:
-
-
-
- ``` example
- line="one::three"
- print -l "${(s.:.)line}"
- ```
-
-
-
- produces two lines of output for `one` and `three` and elides the
- empty field. To override this behaviour, supply the ‘`(@)`’ flag as
- well, i.e. `"${(@s.:.)line}"`.
+Q
+Remove one level of quotes from the resulting words.
- - `Z:``opts``:`
- As `z` but takes a combination of option letters between a following
- pair of delimiter characters. With no options the effect is
- identical to `z`. `(Z+c+)` 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. `(Z+C+)` causes comments to
- be parsed and removed. The rule for comments is standard: anything
- between a word starting with the third character of `$HISTCHARS`,
- default `#`, up to the next newline is a comment. `(Z+n+)` causes
- unquoted newlines to be treated as ordinary whitespace, else they
- are treated as if they are shell code delimiters and converted to
- semicolons. Options are combined within the same set of delimiters,
- e.g. `(Z+Cn+)`.
+t
+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 (‘-’). The first keyword in the string describes
+the main type, it can be one of ‘scalar’, ‘array’, ‘integer’, ‘float’ or
+‘association’. The other keywords describe the type in more detail:
- - `_:``flags``:`
- The underscore (`_`) flag is reserved for future use. As of this
- revision of zsh, there are no valid `flags`; anything following an
- underscore, other than an empty pair of delimiters, is treated as an
- error, and the flag itself has no effect.
+local
+for local parameters
-The following flags are meaningful with the `${`...`#`...`}` or
-`${`...`%`...`}` forms. The `S` and `I` flags may also be used with the
-`${`...`/`...`}` forms.
+left
+for left justified parameters
- - `S`
- With `#` or `##`, search for the match that starts closest to the
- start of the string (a ‘substring match’). Of all matches at a
- particular position, `#` selects the shortest and `##` the longest:
-
-
-
- ``` example
- % str="aXbXc"
- % echo ${(S)str#X*}
- abXc
- % echo ${(S)str##X*}
- a
- %
- ```
-
-
-
- With `%` or `%%`, search for the match that starts closest to the
- end of the string:
-
-
-
- ``` example
- % str="aXbXc"
- % echo ${(S)str%X*}
- aXbc
- % echo ${(S)str%%X*}
- aXb
- %
- ```
-
-
-
- (Note that `%` and `%%` don’t search for the match that ends closest
- to the end of the string, as one might expect.)
-
- With substitution via `${`...`/`...`}` or `${`...`//`...`}`,
- specifies non-greedy matching, i.e. that the shortest instead of the
- longest match should be replaced:
-
-
-
- ``` example
- % str="abab"
- % echo ${str/*b/_}
- _
- % echo ${(S)str/*b/_}
- _ab
- %
- ```
-
-
+right_blanks
+for right justified parameters with leading blanks
- - `I:``expr``:`
- Search the `expr`th match (where `expr` evaluates to a number). This
- only applies when searching for substrings, either with the `S`
- flag, or with `${`...`/`...`}` (only the `expr`th match is
- substituted) or `${`...`//`...`}` (all matches from the `expr`th on
- are substituted). The default is to take the first match.
-
- The `expr`th 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 `${`...`%`...`}` and `${`...`%%`...`}` 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
-
-
-
- ``` example
- which switch is the right switch for Ipswich?
- ```
-
-
-
- substitutions of the form `${`(`SI:``N``:`)`string#w*ch}` as `N`
- increases from 1 will match and remove ‘`which`’, ‘`witch`’,
- ‘`witch`’ and ‘`wich`’; the form using ‘`##`’ will match and
- remove ‘`which switch is the right switch for Ipswich`’, ‘`witch is
- the right switch for Ipswich`’, ‘`witch for Ipswich`’ and ‘`wich`’.
- The form using ‘`%`’ will remove the same matches as for ‘`#`’, but
- in reverse order, and the form using ‘`%%`’ will remove the same
- matches as for ‘`##`’ in reverse order.
+right_zeros
+for right justified parameters with leading zeros
- - `B`
- Include the index of the beginning of the match in the result.
+lower
+for parameters whose value is converted to all lower case when it is
+expanded
- - `E`
- Include the index one character past the end of the match in the
- result (note this is inconsistent with other uses of parameter
- index).
+upper
+for parameters whose value is converted to all upper case when it is
+expanded
- - `M`
- Include the matched portion in the result.
+readonly
+for readonly parameters
- - `N`
- Include the length of the match in the result.
+tag
+for tagged parameters
- - `R`
- Include the unmatched portion in the result (the *R*est).
+tied
+for parameters tied to another parameter in the manner of PATH
+(colon-separated list) and path (array), whether these are special
+parameters or user-defined with ‘typeset -T’
------
+export
+for exported parameters
+
+unique
+for arrays which keep only the first occurrence of duplicated values
+
+hide
+for parameters with the ‘hide’ flag
+
+hideval
+for parameters with the ‘hideval’ flag
+
+special
+for special parameters defined by the shell
+
+u
+Expand only the first occurrence of each unique word.
+
+U
+Convert all letters in the result to upper case.
+
+v
+Used with k, 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.
+
+V
+Make any special characters in the resulting words visible.
+
+w
+With ${#`name`}, count words in arrays or strings; the s flag may be
+used to set a word delimiter.
+
+W
+Similar to w with the difference that empty words between repeated
+delimiters are also counted.
+
+X
+With this flag, parsing errors occurring with the Q, e and # flags or
+the pattern matching forms such as ‘${`name`#`pattern`}’ are reported.
+Without the flag, errors are silently ignored.
+
+z
+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 INTERACTIVE_COMMENTS option unset (however,
+see the Z flag below for related options)
+
+Note that this is done very late, even later than the ‘(s)’ flag. So to
+access single words in the result use nested expansions as in
+‘${${(z)foo}\[2\]}’. Likewise, to remove the quotes in the resulting
+words use ‘${(Q)${(z)foo}}’.
+
+0
+Split the result of the expansion on null bytes. This is a shorthand for
+‘ps:\\0:’.
+
+The following flags (except p) are followed by one or more arguments as
+shown. Any character, or the matching pairs ‘(...)’, ‘{...}’, ‘\[...\]’,
+or ‘\<...>’, 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.
+
+p
+Recognize the same escape sequences as the print builtin in string
+arguments to any of the flags described below that follow this argument.
+
+Alternatively, with this option string arguments may be in the form
+$`var` in which case the value of the variable is substituted. Note this
+form is strict; the string argument does not undergo general parameter
+expansion.
+
+For example,
+
+
+
+```zsh
+sep=:
+val=a:b:c
+print ${(ps.$sep.)val}
+```
+
+
+
+splits the variable on a :.
+
+\~
+Strings inserted into the expansion by any of the flags below are to be
+treated as patterns. This applies to the string arguments of flags that
+follow \~ within the same set of parentheses. Compare with \~ outside
+parentheses, which forces the entire substituted string to be treated as
+a pattern. Hence, for example,
+
+
+
+```zsh
+[[ "?" = ${(~j.|.)array} ]]
+```
+
+
+
+treats ‘\|’ as a pattern and succeeds if and only if $array contains the
+string ‘?’ as an element. The \~ may be repeated to toggle the
+behaviour; its effect only lasts to the end of the parenthesised group.
+
+j:`string`:
+Join the words of arrays together using `string` as a separator.
Note that this
+occurs before field splitting by the s:`string`: flag or the
+SH_WORD_SPLIT option.
+
+l:`expr`::`string1`::`string2`:
+Pad the resulting words on the left. Each word will be truncated if
+required and placed in a field `expr` characters wide.
+
+The arguments :`string1`: and :`string2`: 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 `string1` (concatenated as often as needed) or spaces if
+`string1` is not given. If both `string1` and `string2` are given,
+`string2` is inserted once directly to the left of each word, truncated
+if necessary, before `string1` is used to produce any remaining padding.
+
+If either of `string1` or `string2` is present but empty, i.e. there are
+two delimiters together at that point, the first character of $IFS is
+used instead.
+
+If the MULTIBYTE option is in effect, the flag m 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 MULTIBYTE 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.
+
+m
+Only useful together with one of the flags l or r or with the # length
+operator when the MULTIBYTE option is in effect. Use the character width
+reported by the system in calculating how much of the string it occupies
+or the overall unit, however certain Asian character sets and certain
+special effects use wider characters; combining characters have zero
+width. would actually be displayed will vary.
+
+If the m is repeated, the character either counts zero (if it has 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).
+
+r:`expr`::`string1`::`string2`:
+As l, but pad the words on the right and insert `string2` 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.
+
+s:`string`:
+Force field splitting at the separator `string`. Note that a `string` 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 IFS
+parameter. See also the = flag and the SH_WORD_SPLIT option. An empty
+string may also be given in which case every character will be a
+separate element.
+
+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:
+
+
+
+```zsh
+line="one::three"
+print -l "${(s.:.)line}"
+```
+
+
+
+produces two lines of output for one and three and elides the empty
+field. To override this behaviour, supply the ‘(@)’ flag as well, i.e.
+"${(@s.:.)line}".
+
+Z:`opts`:
+As z but takes a combination of option letters between a following pair
+of delimiter characters. With no options the effect is identical to z.
+The following options are available:
+
+(Z+c+)
+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.
+
+(Z+C+)
+causes comments to be parsed and removed. The rule for comments is
+standard: anything between a word starting with the third character of
+$HISTCHARS, default #, up to the next newline is a comment.
+
+(Z+n+)
+causes unquoted newlines to be treated as ordinary whitespace, else they
+are treated as if they are shell code delimiters and converted to
+semicolons.
+
+Options are combined within the same set of delimiters, e.g. (Z+Cn+).
+
+\_:`flags`:
+The underscore (\_) flag is reserved for future use. As of this revision
+of zsh, there are no valid `flags`; 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 ${...#...} or ${...%...}
+forms. The S, I, and \* flags may also be used with the ${.../...}
+forms.
+
+S
+With # or ##, search for the match that starts closest to the start of
+the string (a ‘substring match’). Of all matches at a particular
+position, # selects the shortest and ## the longest:
+
+
+
+```zsh
+% str="aXbXc"
+% echo ${(S)str#X*}
+abXc
+% echo ${(S)str##X*}
+a
+%
+```
+
+
+
+With % or %%, search for the match that starts closest to the end of the
+string:
+
+
+
+```zsh
+% str="aXbXc"
+% echo ${(S)str%X*}
+aXbc
+% echo ${(S)str%%X*}
+aXb
+%
+```
+
+
+
+(Note that % and %% don’t search for the match that ends closest to the
+end of the string, as one might expect.)
+
+With substitution via ${.../...} or ${...//...}, specifies non-greedy
+matching, i.e. that the shortest instead of the longest match should be
+replaced:
+
+
+
+```zsh
+% str="abab"
+% echo ${str/*b/_}
+_
+% echo ${(S)str/*b/_}
+_ab
+%
+```
+
+
+
+I:`expr`:
+Search the `expr`th match (where `expr` evaluates to a number). This
+only applies when searching for substrings, either with the S flag, or
+with ${.../...} (only the `expr`th match is substituted) or ${...//...}
+(all matches from the `expr`th on are substituted). The default is to
+take the first match.
+
+The `expr`th 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 ${...%...} and ${...%%...} 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
+
+
+
+```zsh
+which switch is the right switch for Ipswich?
+```
+
+
+
+substitutions of the form ${(SI:`N`:)string#w\*ch} as `N` increases from
+1 will match and remove ‘which’, ‘witch’, ‘witch’ and ‘wich’; the form
+using ‘##’ will match and remove ‘which switch is the right switch for
+Ipswich’, ‘witch is the right switch for Ipswich’, ‘witch for Ipswich’
+and ‘wich’. The form using ‘%’ will remove the same matches as for ‘#’,
+but in reverse order, and the form using ‘%%’ will remove the same
+matches as for ‘##’ in reverse order.
+
+\*
+
+
+Enable EXTENDED_GLOB for substitution via ${.../...} or ${...//...}.
+Note that ‘\*\*’ does not disable extendedglob.
+
+B
+Include the index of the beginning of the match in the result.
+
+E
+Include the index one character past the end of the match in the result
+(note this is inconsistent with other uses of parameter index).
+
+M
+Include the matched portion in the result.
+
+N
+Include the length of the match in the result.
+
+R
+Include the unmatched portion in the result (the *R*est).
+
+------------------------------------------------------------------------
### 14.3.2 Rules
+
+
Here is a summary of the rules for substitution; this assumes that
-braces are present around the substitution, i.e. `${``...``}`. Some
+braces are present around the substitution, i.e. ${`...`}. Some
particular examples are given below. Note that the Zsh Development Group
accepts *no responsibility* for any brain damage which may occur during
the reading of the following rules.
- - `1.` *Nested substitution*
- If multiple nested `${``...``}` 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 ‘`(P)`’ flag is present, the flags and any
- subscripts apply directly to the value of the nested substitution;
- for example, the expansion `${${foo}}` behaves exactly the same as
- `${foo}`. When the ‘`(P)`’ flag is present in a nested substitution,
- the other substitution rules are applied to the value *before* it is
- interpreted as a name, so `${${(P)foo}}` may differ from
- `${(P)foo}`.
-
- 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 `~` and `=`). Thus, for
- example, `${${:-=cat}:h}` expands to the directory where the `cat`
- program resides. (Explanation: the internal substitution has no
- parameter but a default value `=cat`, which is expanded by filename
- expansion to a full path; the outer substitution then applies the
- modifier `:h` and takes the directory part of the path.)
+1\. *Nested substitution*
+If multiple nested ${`...`} 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.
- - `2.` *Internal parameter flags*
- Any parameter flags set by one of the `typeset` family of commands,
- in particular the `-L`, `-R`, `-Z`, `-u` and `-l` options for
- padding and capitalization, are applied directly to the parameter
- value. Note these flags are options to the command, e.g. ‘`typeset
- -Z`’; they are not the same as the flags used within parameter
- substitutions.
-
- At the outermost level of substitution, the ‘`(P)`’ flag (rule `4.`)
- ignores these transformations and uses the unmodified value of the
- parameter as the name to be replaced. This is usually the desired
- behavior because padding may make the value syntactically illegal as
- a parameter name, but if capitalization changes are desired, use the
- `${${(P)foo}}` form (rule `25.`).
+Note that, unless the ‘(P)’ flag is present, the flags and any
+subscripts apply directly to the value of the nested substitution; for
+example, the expansion ${${foo}} behaves exactly the same as ${foo}.
+When the ‘(P)’ flag is present in a nested substitution, the other
+substitution rules are applied to the value *before* it is interpreted
+as a name, so ${${(P)foo}} may differ from ${(P)foo}.
- - `3.` *Parameter subscripting*
- If the value is a raw parameter reference with a subscript, such as
- `${``var``[3]}`, 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 `var` is an array, `${var[1][2]}` is the
- second character of the first word, but `${var[2,4][2]}` 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.
- Flags such as ‘`(k)`’ and ‘`(v)`’ which alter the result of
- subscripting are applied.
+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 \~ and =). Thus, for example, ${${:-=cat}:h}
+expands to the directory where the cat program resides. (Explanation:
+the internal substitution has no parameter but a default value =cat,
+which is expanded by filename expansion to a full path; the outer
+substitution then applies the modifier :h and takes the directory part
+of the path.)
- - `4.` *Parameter name replacement*
- At the outermost level of nesting only, the ‘`(P)`’ flag is applied.
- This treats the value so far as a parameter name (which may include
- a subscript expression) and replaces that with the corresponding
- value. This replacement occurs later if the ‘`(P)`’ flag appears in
- a nested substitution.
-
- If the value so far names a parameter that has internal flags (rule
- `2.`), those internal flags are applied to the new value after
- replacement.
+2\. *Internal parameter flags*
+Any parameter flags set by one of the typeset family of commands, in
+particular the -L, -R, -Z, -u and -l options for padding and
+capitalization, are applied directly to the parameter value. Note these
+flags are options to the command, e.g. ‘typeset -Z’; they are not the
+same as the flags used within parameter substitutions.
- - `5.` *Double-quoted joining*
- If the value after this process is an array, and the substitution
- appears in double quotes, and neither an ‘`(@)`’ flag nor a ‘`#`’
- length operator is present at the current level, then words of the
- value are joined with the first character of the parameter `$IFS`,
- by default a space, between each word (single word arrays are not
- modified). If the ‘`(j)`’ flag is present, that is used for joining
- instead of `$IFS`.
+At the outermost level of substitution, the ‘(P)’ flag (rule 4.) ignores
+these transformations and uses the unmodified value of the parameter as
+the name to be replaced. This is usually the desired behavior because
+padding may make the value syntactically illegal as a parameter name,
+but if capitalization changes are desired, use the ${${(P)foo}} form
+(rule 25.).
- - `6.` *Nested subscripting*
- 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 `3.`, multiple subscripts can appear. Note that
- `${foo[2,4][2]}` is thus equivalent to `${${foo[2,4]}[2]}` and also
- to `"${${(@)foo[2,4]}[2]}"` (the nested substitution returns an
- array in both cases), but not to `"${${foo[2,4]}[2]}"` (the nested
- substitution returns a scalar because of the quotes).
+3\. *Parameter subscripting*
+If the value is a raw parameter reference with a subscript, such as
+${`var`\[3\]}, 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 var is an array, ${var\[1\]\[2\]} is the second character of the
+first word, but ${var\[2,4\]\[2\]} 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. Flags such as ‘(k)’ and ‘(v)’ which
+alter the result of subscripting are applied.
- - `7.` *Modifiers*
- Any modifiers, as specified by a trailing ‘`#`’, ‘`%`’, ‘`/`’
- (possibly doubled) or by a set of modifiers of the form ‘`:...`’
- (see [Modifiers](#Modifiers) in [History
- Expansion](#History-Expansion)), are applied to the words of the
- value at this level.
+4\. *Parameter name replacement*
+At the outermost level of nesting only, the ‘(P)’ flag is applied. This
+treats the value so far as a parameter name (which may include a
+subscript expression) and replaces that with the corresponding value.
+This replacement occurs later if the ‘(P)’ flag appears in a nested
+substitution.
- - `8.` *Character evaluation*
- Any ‘`(#)`’ flag is applied, evaluating the result so far
- numerically as a character.
+If the value so far names a parameter that has internal flags (rule 2.),
+those internal flags are applied to the new value after replacement.
- - `9.` *Length*
- Any initial ‘`#`’ modifier, i.e. in the form `${#``var``}`, is used
- to evaluate the length of the expression so far.
+5\. *Double-quoted joining*
+If the value after this process is an array, and the substitution
+appears in double quotes, and neither an ‘(@)’ flag nor a ‘#’ length
+operator is present at the current level, then words of the value are
+joined with the first character of the parameter $IFS, by default a
+space, between each word (single word arrays are not modified). If the
+‘(j)’ flag is present, that is used for joining instead of $IFS.
- - `10.` *Forced joining*
- If the ‘`(j)`’ flag is present, or no ‘`(j)`’ flag is present but
- the string is to be split as given by rule `11.`, and joining did
- not take place at rule `5.`, any words in the value are joined
- together using the given string or the first character of `$IFS` if
- none. Note that the ‘`(F)`’ flag implicitly supplies a string for
- joining in this manner.
+6\. *Nested subscripting*
+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 3., multiple subscripts can appear. Note that ${foo\[2,4\]\[2\]} is
+thus equivalent to ${${foo\[2,4\]}\[2\]} and also to
+"${${(@)foo\[2,4\]}\[2\]}" (the nested substitution returns an array in
+both cases), but not to "${${foo\[2,4\]}\[2\]}" (the nested substitution
+returns a scalar because of the quotes).
- - `11.` *Simple word splitting*
- If one of the ‘`(s)`’ or ‘`(f)`’ flags are present, or the ‘`=`’
- specifier was present (e.g. `${=``var``}`), the word is split on
- occurrences of the specified string, or (for `=` with neither of the
- two flags present) any of the characters in `$IFS`.
-
- If no ‘`(s)`’, ‘`(f)`’ or ‘`=`’ was given, but the word is not
- quoted and the option `SH_WORD_SPLIT` is set, the word is split on
- occurrences of any of the characters in `$IFS`. Note this step, too,
- takes place at all levels of a nested substitution.
+7\. *Modifiers*
+Any modifiers, as specified by a trailing ‘#’, ‘%’, ‘/’ (possibly
+doubled) or by a set of modifiers of the form ‘:...’ (see
+[Modifiers](#Modifiers) in [History Expansion](#History-Expansion)), are
+applied to the words of the value at this level.
- - `12.` *Case modification*
- Any case modification from one of the flags ‘`(L)`’, ‘`(U)`’ or
- ‘`(C)`’ is applied.
+8\. *Character evaluation*
+Any ‘(#)’ flag is applied, evaluating the result so far numerically as a
+character.
- - `13.` *Escape sequence replacement*
- First any replacements from the ‘`(g)`’ flag are performed, then any
- prompt-style formatting from the ‘`(%)`’ family of flags is applied.
+9\. *Length*
+Any initial ‘#’ modifier, i.e. in the form ${#`var`}, is used to
+evaluate the length of the expression so far.
- - `14.` *Quote application*
- Any quoting or unquoting using ‘`(q)`’ and ‘`(Q)`’ and related flags
- is applied.
+10\. *Forced joining*
+If the ‘(j)’ flag is present, or no ‘(j)’ flag is present but the string
+is to be split as given by rule 11., and joining did not take place at
+rule 5., any words in the value are joined together using the given
+string or the first character of $IFS if none. Note that the ‘(F)’ flag
+implicitly supplies a string for joining in this manner.
- - `15.` *Directory naming*
- Any directory name substitution using ‘`(D)`’ flag is applied.
+11\. *Simple word splitting*
+If one of the ‘(s)’ or ‘(f)’ flags are present, or the ‘=’ specifier was
+present (e.g. ${=`var`}), the word is split on occurrences of the
+specified string, or (for = with neither of the two flags present) any
+of the characters in $IFS.
- - `16.` *Visibility enhancement*
- Any modifications to make characters visible using the ‘`(V)`’ flag
- are applied.
+If no ‘(s)’, ‘(f)’ or ‘=’ was given, but the word is not quoted and the
+option SH_WORD_SPLIT is set, the word is split on occurrences of any of
+the characters in $IFS. Note this step, too, takes place at all levels
+of a nested substitution.
- - `17.` *Lexical word splitting*
- If the ’`(z)`’ flag or one of the forms of the ’`(Z)`’ flag is
- present, the word is split as if it were a shell command line, so
- that quotation marks and other metacharacters are used to decide
- what constitutes a word. Note this form of splitting is entirely
- distinct from that described by rule `11.`: it does not use `$IFS`,
- and does not cause forced joining.
+12\. *Case modification*
+Any case modification from one of the flags ‘(L)’, ‘(U)’ or ‘(C)’ is
+applied.
- - `18.` *Uniqueness*
- If the result is an array and the ‘`(u)`’ flag was present,
- duplicate elements are removed from the array.
+13\. *Escape sequence replacement*
+First any replacements from the ‘(g)’ flag are performed, then any
+prompt-style formatting from the ‘(%)’ family of flags is applied.
- - `19.` *Ordering*
- If the result is still an array and one of the ‘`(o)`’ or ‘`(O)`’
- flags was present, the array is reordered.
+14\. *Quote application*
+Any quoting or unquoting using ‘(q)’ and ‘(Q)’ and related flags is
+applied.
- - `20.` `RC_EXPAND_PARAM`
- At this point the decision is made whether any resulting array
- elements are to be combined element by element with surrounding
- text, as given by either the `RC_EXPAND_PARAM` option or the ‘`^`’
- flag.
+15\. *Directory naming*
+Any directory name substitution using ‘(D)’ flag is applied.
- - `21.` *Re-evaluation*
- Any ‘`(e)`’ flag is applied to the value, forcing it to be
- re-examined for new parameter substitutions, but also for command
- and arithmetic substitutions.
+16\. *Visibility enhancement*
+Any modifications to make characters visible using the ‘(V)’ flag are
+applied.
- - `22.` *Padding*
- Any padding of the value by the ‘`(l.``fill``.)`’ or
- ‘`(r.``fill``.)`’ flags is applied.
+17\. *Lexical word splitting*
+If the ’(z)’ flag or one of the forms of the ’(Z)’ flag is present, the
+word is split as if it were a shell command line, so that quotation
+marks and other metacharacters are used to decide what constitutes a
+word. Note this form of splitting is entirely distinct from that
+described by rule 11.: it does not use $IFS, and does not cause forced
+joining.
- - `23.` *Semantic joining*
- In contexts where expansion semantics requires a single word to
- result, all words are rejoined with the first character of `IFS`
- between. So in ‘`${(P``)${(f``)lines}}`’ the value of `${lines}` is
- split at newlines, but then must be joined again before the ‘`(P)`’
- flag can be applied.
-
- If a single word is not required, this rule is skipped.
+18\. *Uniqueness*
+If the result is an array and the ‘(u)’ flag was present, duplicate
+elements are removed from the array.
- - `24.` *Empty argument removal*
- 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.
+19\. *Ordering*
+If the result is still an array and one of the ‘(o)’ or ‘(O)’ flags was
+present, the array is reordered.
- - `25.` *Nested parameter name replacement*
- If the ‘`(P)`’ flag is present and rule `4.` has not applied, the
- value so far is treated as a parameter name (which may include a
- subscript expression) and replaced with the corresponding value,
- with internal flags (rule `2.`) applied to the new value.
+20\. RC_EXPAND_PARAM
+At this point the decision is made whether any resulting array elements
+are to be combined element by element with surrounding text, as given by
+either the RC_EXPAND_PARAM option or the ‘^’ flag.
------
+21\. *Re-evaluation*
+Any ‘(e)’ flag is applied to the value, forcing it to be re-examined for
+new parameter substitutions, but also for command and arithmetic
+substitutions.
-
+22\. *Padding*
+Any padding of the value by the ‘(l.`fill`.)’ or ‘(r.`fill`.)’ flags is
+applied.
+
+23\. *Semantic joining*
+In contexts where expansion semantics requires a single word to result,
+all words are rejoined with the first character of IFS between. So in
+‘${(P)${(f)lines}}’ the value of ${lines} is split at newlines, but then
+must be joined again before the ‘(P)’ flag can be applied.
+
+If a single word is not required, this rule is skipped.
+
+24\. *Empty argument removal*
+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.
+
+25\. *Nested parameter name replacement*
+If the ‘(P)’ flag is present and rule 4. has not applied, the value so
+far is treated as a parameter name (which may include a subscript
+expression) and replaced with the corresponding value, with internal
+flags (rule 2.) applied to the new value.
+
+------------------------------------------------------------------------
+
+
### 14.3.3 Examples
-The flag `f` is useful to split a double-quoted substitution line by
-line. For example, `${(f)"$(<``file``)"}` substitutes the contents of
-`file` divided so that each line is an element of the resulting array.
-Compare this with the effect of `$``(<``file``)` 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 flag f is useful to split a double-quoted substitution line by line.
+For example, ${(f)"$(\<`file`)"} substitutes the contents of `file`
+divided so that each line is an element of the resulting array. Compare
+this with the effect of $(\<`file`) 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 `$foo` contains the array `(bar baz``)`:
+Suppose that $foo contains the array (bar baz):
- - `"${(@)${foo}[1]}"`
- This produces the result `b`. First, the inner substitution
- `"${foo}"`, which has no array (`@`) flag, produces a single word
- result `"bar baz"`. The outer substitution `"${(@)...[1]}"` detects
- that this is a scalar, so that (despite the ‘`(@)`’ flag) the
- subscript picks the first character.
+"${(@)${foo}\[1\]}"
+This produces the result b. First, the inner substitution "${foo}",
+which has no array (@) flag, produces a single word result "bar baz".
+The outer substitution "${(@)...\[1\]}" detects that this is a scalar,
+so that (despite the ‘(@)’ flag) the subscript picks the first
+character.
- - `"${${(@)foo}[1]}"`
- This produces the result ‘`bar`’. In this case, the inner
- substitution `"${(@)foo}"` produces the array ‘`(bar baz``)`’. The
- outer substitution `"${...[1]}"` detects that this is an array and
- picks the first word. This is similar to the simple case
- `"${foo[1]}"`.
+"${${(@)foo}\[1\]}"
+This produces the result ‘bar’. In this case, the inner substitution
+"${(@)foo}" produces the array ‘(bar baz)’. The outer substitution
+"${...\[1\]}" detects that this is an array and picks the first word.
+This is similar to the simple case "${foo\[1\]}".
-As an example of the rules for word splitting and joining, suppose
-`$foo` contains the array ‘`(ax1 bx1``)`’. Then
+As an example of the rules for word splitting and joining, suppose $foo
+contains the array ‘(ax1 bx1)’. Then
- - `${(s/x/)foo}`
- produces the words ‘`a`’, ‘`1 b`’ and ‘`1`’.
+${(s/x/)foo}
+produces the words ‘a’, ‘1 b’ and ‘1’.
- - `${(j/x/s/x/)foo}`
- produces ‘`a`’, ‘`1`’, ‘`b`’ and ‘`1`’.
+${(j/x/s/x/)foo}
+produces ‘a’, ‘1’, ‘b’ and ‘1’.
- - `${(s/x/)foo%%1*}`
- produces ‘`a`’ and ‘` b `’ (note the extra space). As substitution
- occurs before either joining or splitting, the operation first
- generates the modified array `(ax bx``)`, which is joined to give
- `"ax bx"`, and then split to give ‘`a`’, ‘` b `’ and ‘’. The final
- empty string will then be elided, as it is not in double quotes.
+${(s/x/)foo%%1\*}
+produces ‘a’ and ‘ b’ (note the extra space). As substitution occurs
+before either joining or splitting, the operation first generates the
+modified array (ax bx), which is joined to give "ax bx", and then split
+to give ‘a’, ‘ b’ and ‘’. The final empty string will then be elided, as
+it is not in double quotes.
------
+------------------------------------------------------------------------
-
-
+
## 14.4 Command Substitution
-
-
+
A command enclosed in parentheses preceded by a dollar sign, like
-‘`$(`...`)`’, or quoted with grave accents, like ‘`‘`...`‘`’, 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 `IFS` parameter.
-
+‘$(...)’, or quoted with grave accents, like ‘‘...‘’, 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 IFS parameter.
-The substitution ‘`$(cat` `foo``)`’ may be replaced by the faster
-‘`$(<``foo``)`’. In this case `foo` undergoes single word shell
-expansions (*parameter expansion*, *command substitution* and
-*arithmetic expansion*), but not filename generation.
+The substitution ‘$(cat `foo`)’ may be replaced by the faster
+‘$(\<`foo`)’. In this case `foo` undergoes single word shell expansions
+(*parameter expansion*, *command substitution* and *arithmetic
+expansion*), but not filename generation.
-If the option `GLOB_SUBST` is set, the result of any unquoted command
+If the option GLOB_SUBST is set, the result of any unquoted command
substitution, including the special form just mentioned, is eligible for
filename generation.
------
+------------------------------------------------------------------------
-
-
+
## 14.5 Arithmetic Expansion
-
-
+
-A string of the form ‘`$[``exp``]`’ or ‘`$((``exp``))`’ is substituted
-with the value of the arithmetic expression `exp`. `exp` is subjected to
+A string of the form ‘$\[`exp`\]’ or ‘$((`exp`))’ is substituted with
+the value of the arithmetic expression `exp`. `exp` is subjected to
*parameter expansion*, *command substitution* and *arithmetic expansion*
before it is evaluated. See [Arithmetic
Evaluation](Arithmetic-Evaluation.html#Arithmetic-Evaluation).
------
+------------------------------------------------------------------------
## 14.6 Brace Expansion
-
-
+
-A string of the form ‘`foo``{``xx``,``yy``,``zz``}``bar`’ is expanded to
-the individual words ‘`fooxxbar`’, ‘`fooyybar`’ and ‘`foozzbar`’.
+A string of the form ‘`foo`{`xx`,`yy`,`zz`}`bar`’ is expanded to the
+individual words ‘`fooxxbar`’, ‘`fooyybar`’ and ‘`foozzbar`’.
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 ‘`{``n1``..``n2``}`’, where `n1` and `n2` are
+An expression of the form ‘{`n1`..`n2`}’, where `n1` and `n2` are
integers, is expanded to every number between `n1` and `n2` 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 `-` character is also included in the width. If the numbers
+numbers the - 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 ‘`{``n1``..``n2``..``n3``}`’, where `n1`,
-`n2`, and `n3` are integers, is expanded as above, but only every `n3`th
-number starting from `n1` is output. If `n3` is negative the numbers are
-output in reverse order, this is slightly different from simply swapping
-`n1` and `n2` in the case that the step `n3` 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
-‘`{-99..100..01}`’ which is not possible to specify by putting a 0 on
-either of the first two numbers (i.e. pad to two characters).
+An expression of the form ‘{`n1`..`n2`..`n3`}’, where `n1`, `n2`, and
+`n3` are integers, is expanded as above, but only every `n3`th number
+starting from `n1` is output. If `n3` is negative the numbers are output
+in reverse order, this is slightly different from simply swapping `n1`
+and `n2` in the case that the step `n3` 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 ‘{-99..100..01}’ which is
+not possible to specify by putting a 0 on either of the first two
+numbers (i.e. pad to two characters).
-An expression of the form ‘`{``c1``..``c2``}`’, where `c1` and `c2` are
-single characters (which may be multibyte characters), is expanded to
-every character in the range from `c1` to `c2` in whatever character
-sequence is used internally. For characters with code points below 128
-this is US ASCII (this is the only case most users will need). If any
-intervening character is not If the character sequence is reversed, the
-output is in reverse order, e.g. ‘`{d..a}`’ is substituted as ‘`d c b
-a`’.
+An expression of the form ‘{`c1`..`c2`}’, where `c1` and `c2` are single
+characters (which may be multibyte characters), is expanded to every
+character in the range from `c1` to `c2` in whatever character sequence
+is used internally. For characters with code points below 128 this is US
+ASCII (this is the only case most users will need). If any intervening
+character is not If the character sequence is reversed, the output is in
+reverse order, e.g. ‘{d..a}’ is substituted as ‘d c b a’.
If a brace expression matches none of the above forms, it is left
-unchanged, unless the option `BRACE_CCL` (an abbreviation for ‘brace
-character class’) is set.
-
In that case, it is
+unchanged, unless the option BRACE_CCL (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 `[`...`]` expression in filename generation: ‘`-`’ is treated
-specially to denote a range of characters, but ‘`^`’ or ‘`!`’ as the
-first character is treated normally. For example, ‘`{abcdef0-9}`’
-expands to 16 words `0 1 2 3 4 5 6 7 8 9 a b c d e f`.
+to a \[...\] expression in filename generation: ‘-’ is treated specially
+to denote a range of characters, but ‘^’ or ‘!’ as the first character
+is treated normally. For example, ‘{abcdef0-9}’ expands to 16 words 0 1
+2 3 4 5 6 7 8 9 a b c d e f.
Note that brace expansion is not part of filename generation (globbing);
-an expression such as `*/{foo,bar}` is split into two separate words
-`*/foo` and `*/bar` before filename generation takes place. In
-particular, note that this is liable to produce a ‘no match’ error if
-*either* of the two expressions does not match; this is to be contrasted
-with `*/(foo|bar)`, which is treated as a single pattern but otherwise
-has similar effects.
+an expression such as \*/{foo,bar} is split into two separate words
+\*/foo and \*/bar before filename generation takes place. In particular,
+note that this is liable to produce a ‘no match’ error if *either* of
+the two expressions does not match; this is to be contrasted with
+\*/(foo\|bar), which is treated as a single pattern but otherwise has
+similar effects.
-To combine brace expansion with array expansion, see the `${^``spec``}`
-form described in [Parameter Expansion](#Parameter-Expansion) above.
+To combine brace expansion with array expansion, see the ${^`spec`} form
+described in [Parameter Expansion](#Parameter-Expansion) above.
------
+------------------------------------------------------------------------
-
-
+
## 14.7 Filename Expansion
-
-
+
-Each word is checked to see if it begins with an unquoted ‘`~`’. If it
-does, then the word up to a ‘`/`’, or the end of the word if there is no
-‘`/`’, is checked to see if it can be substituted in one of the ways
-described here. If so, then the ‘`~`’ and the checked portion are
+Each word is checked to see if it begins with an unquoted ‘\~’. If it
+does, then the word up to a ‘/’, or the end of the word if there is no
+‘/’, is checked to see if it can be substituted in one of the ways
+described here. If so, then the ‘\~’ and the checked portion are
replaced with the appropriate substitute value.
-A ‘`~`’ by itself is replaced by the value of `$HOME`. A ‘`~`’ followed
-by a ‘`+`’ or a ‘`-`’ is replaced by current or previous working
-directory, respectively.
+A ‘\~’ by itself is replaced by the value of $HOME. A ‘\~’ followed by a
+‘+’ or a ‘-’ is replaced by current or previous working directory,
+respectively.
-A ‘`~`’ followed by a number is replaced by the directory at that
-position in the directory stack. ‘`~0`’ is equivalent to ‘`~+`’, and
-‘`~1`’ is the top of the stack. ‘`~+`’ followed by a number is
-replaced by the directory at that position in the directory stack.
-‘`~+0`’ is equivalent to ‘`~+`’, and ‘`~+1`’ is the top of the stack.
-‘`~-`’ followed by a number is replaced by the directory that many
-positions from the bottom of the stack. ‘`~-0`’ is the bottom of the
-stack.
The
-`PUSHD_MINUS` option exchanges the effects of ‘`~+`’ and ‘`~-`’ where
-they are followed by a number.
+A ‘\~’ followed by a number is replaced by the directory at that
+position in the directory stack. ‘\~0’ is equivalent to ‘\~+’, and ‘\~1’
+is the top of the stack. ‘\~+’ followed by a number is replaced by the
+directory at that position in the directory stack. ‘\~+0’ is equivalent
+to ‘\~+’, and ‘\~+1’ is the top of the stack. ‘\~-’ followed by a number
+is replaced by the directory that many positions from the bottom of the
+stack. ‘\~-0’ is the bottom of the stack.
The PUSHD_MINUS option
+exchanges the effects of ‘\~+’ and ‘\~-’ where they are followed by a
+number.
------
+------------------------------------------------------------------------
-
+
### 14.7.1 Dynamic named directories
-
-
-
+
-If the function `zsh_directory_name` exists, or the shell variable
-`zsh_directory_name_functions` exists and contains an array of function
+If the function zsh_directory_name exists, or the shell variable
+zsh_directory_name_functions exists and contains an array of function
names, then the functions are used to implement dynamic directory
naming. The functions are tried in order until one returns status zero,
so it is important that functions test whether they can handle the case
in question and return an appropriate status.
-A ‘`~`’ followed by a string `namstr` in unquoted square brackets is
+A ‘\~’ followed by a string `namstr` in unquoted square brackets is
treated specially as a dynamic directory name. Note that the first
unquoted closing square bracket always terminates `namstr`. The shell
-function is passed two arguments: the string `n` (for name) and
-`namstr`. It should either set the array `reply` 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. If all functions fail and the option `NOMATCH` is
-set, an error results.
+function is passed two arguments: the string n (for name) and `namstr`.
+It should either set the array reply 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. If all functions fail and the option NOMATCH is set, an error
+results.
The functions defined as above are also used to see if a directory can
be turned into a name, for example when printing the directory stack or
-when expanding `%~` in prompts. In this case each function is passed two
-arguments: the string `d` (for directory) and the candidate for dynamic
+when expanding %\~ in prompts. In this case each function is passed two
+arguments: the string d (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 ‘`~[``...``]`’), and the second is the
+directory (as would appear within ‘\~\[`...`\]’), and the second is the
prefix length of the directory to be replaced. For example, if the trial
-directory is `/home/myname/src/zsh` and the dynamic name for
-`/home/myname/src` (which has 16 characters) is `s`, then the function
-sets
+directory is /home/myname/src/zsh and the dynamic name for
+/home/myname/src (which has 16 characters) is s, then the function sets
-``` example
+```zsh
reply=(s 16)
```
@@ -2078,26 +2058,26 @@ 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.
-It is not a requirement that a function implements both `n` and `d`
-calls; for example, it might be appropriate for certain dynamic forms of
+It is not a requirement that a function implements both n and d calls;
+for example, it might be appropriate for certain dynamic forms of
expansion not to be contracted to names. In that case any call with the
-first argument `d` should cause a non-zero status to be returned.
+first argument d should cause a non-zero status to be returned.
-The completion system calls ‘`zsh_directory_name c`’ followed by
-equivalent calls to elements of the array
-`zsh_directory_name_functions`, if it exists, in order to complete
-dynamic names for directories. The code for this should be as for any
-other completion function as described in [Completion
+The completion system calls ‘zsh_directory_name c’ followed by
+equivalent calls to elements of the array zsh_directory_name_functions,
+if it exists, in order to complete dynamic names for directories. The
+code for this should be as for any other completion function as
+described in [Completion
System](Completion-System.html#Completion-System).
As a working example, here is a function that expands any dynamic names
-beginning with the string `p:` to directories below
-`/home/pws/perforce`. In this simple case a static name for the
-directory would be just as effective.
+beginning with the string p: to directories below /home/pws/perforce. In
+this simple case a static name for the directory would be just as
+effective.
-``` example
+```zsh
zsh_directory_name() {
emulate -L zsh
setopt extendedglob
@@ -2132,270 +2112,267 @@ zsh_directory_name() {
------
+------------------------------------------------------------------------
-
+
### 14.7.2 Static named directories
-
-
-
+
-A ‘`~`’ followed by anything not already covered consisting of any
-number of alphanumeric characters or underscore (‘`_`’), hyphen (‘`-`’),
-or dot (‘`.`’) 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 ‘`~`’ is the name of a string shell parameter whose
-value begins with a ‘`/`’. Note that trailing slashes will be removed
-from the path to the directory (though the original parameter is not
-modified).
+A ‘\~’ followed by anything not already covered consisting of any number
+of alphanumeric characters or underscore (‘\_’), hyphen (‘-’), or dot
+(‘.’) 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 ‘\~’ is the name of a string shell parameter whose value
+begins with a ‘/’. 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 `-d` option to
-the `hash` builtin.
+It is also possible to define directory names using the -d option to the
+hash builtin.
-When the shell prints a path (e.g. when expanding `%~` in prompts or
-when printing the directory stack), 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 ‘`~`’ followed by the name of the directory. The shorter
+When the shell prints a path (e.g. when expanding %\~ in prompts or when
+printing the directory stack), 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 ‘\~’ followed by the name of the directory. The shorter
of the two ways of referring to the directory is used, i.e. either the
directory name or the full path; the name is used if they are the same
-length. The parameters `$PWD` and `$OLDPWD` are never abbreviated in
-this fashion.
+length. The parameters $PWD and $OLDPWD are never abbreviated in this
+fashion.
------
+------------------------------------------------------------------------
-
+
### 14.7.3 ‘=’ expansion
-If a word begins with an unquoted ‘`=`’ and the `EQUALS` 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.
+If a word begins with an unquoted ‘=’ and the EQUALS 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.
------
+------------------------------------------------------------------------
-
+
### 14.7.4 Notes
+
+
Filename expansion is performed on the right hand side of a parameter
-assignment, including those appearing after commands of the `typeset`
+assignment, including those appearing after commands of the typeset
family. In this case, the right hand side will be treated as a
-colon-separated list in the manner of the `PATH` parameter, so that a
-‘`~`’ or an ‘`=`’ following a ‘`:`’ is eligible for expansion. All
-such behaviour can be disabled by quoting the ‘`~`’, the ‘`=`’, or the
-whole expression (but not simply the colon); the `EQUALS` option is also
-respected.
+colon-separated list in the manner of the PATH parameter, so that a ‘\~’
+or an ‘=’ following a ‘:’ is eligible for expansion. All such behaviour
+can be disabled by quoting the ‘\~’, the ‘=’, or the whole expression
+(but not simply the colon); the EQUALS option is also respected.
-If the option `MAGIC_EQUAL_SUBST` is set, any unquoted shell argument in
-the form ‘`identifier``=``expression`’ becomes eligible for file
-expansion as described in the previous paragraph. Quoting the first
-‘`=`’ also inhibits this.
+If the option MAGIC_EQUAL_SUBST is set, any unquoted shell argument in
+the form ‘`identifier`=`expression`’ becomes eligible for file expansion
+as described in the previous paragraph. Quoting the first ‘=’ also
+inhibits this.
------
+------------------------------------------------------------------------
-
-
+
## 14.8 Filename Generation
-If a word contains an unquoted instance of one of the characters ‘`*`’,
-‘`(`’, ‘`|`’, ‘`<`’, ‘`[`’, or ‘`?`’, it is regarded as a pattern for
-filename generation, unless the `GLOB` option is unset.
-
If the `EXTENDED_GLOB` option
-is set,
the ‘`^`’
-and ‘`#`’ characters also denote a pattern; otherwise they are not
-treated specially by the shell.
+If a word contains an unquoted instance of one of the characters ‘\*’,
+‘(’, ‘\|’, ‘\<’, ‘\[’, or ‘?’, it is regarded as a pattern for filename
+generation, unless the GLOB option is unset.
If the EXTENDED_GLOB option is set,
+
the ‘^’ and ‘#’
+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 `NULL_GLOB` option is set,
-
in which case the
-word is deleted; or unless the `NOMATCH` option is unset, in which case
-the word is left unchanged.
+message, unless the NULL_GLOB option is set,
in which case the word is
+deleted; or unless the NOMATCH option is unset, in which case the word
+is left unchanged.
-In filename generation, the character ‘`/`’ must be matched explicitly;
-also, a ‘`.`’ must be matched explicitly at the beginning of a pattern
-or after a ‘`/`’, unless the `GLOB_DOTS` option is set.
-
No filename
-generation pattern matches the files ‘`.`’ or ‘`..`’. In other instances
-of pattern matching, the ‘`/`’ and ‘`.`’ are not treated specially.
+In filename generation, the character ‘/’ must be matched explicitly;
+also, a ‘.’ must be matched explicitly at the beginning of a pattern or
+after a ‘/’, unless the GLOB_DOTS option is set.
No filename generation
+pattern matches the files ‘.’ or ‘..’. In other instances of pattern
+matching, the ‘/’ and ‘.’ are not treated specially.
------
+------------------------------------------------------------------------
### 14.8.1 Glob Operators
- - `*`
- Matches any string, including the null string.
+
- - `?`
- Matches any character.
+\*
+Matches any string, including the null string.
- - `[`...`]`
- Matches any of the enclosed characters. Ranges of characters can be
- specified by separating two characters by a ‘`-`’. A ‘`-`’ or ‘`]`’
- may be matched by including it as the first character in the list.
-
There are also several
- named classes of characters, in the form ‘`[:``name``:]`’ 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 man
- page ctype(3):
-
- - `[:alnum:]`
- The character is alphanumeric
-
- - `[:alpha:]`
- The character is alphabetic
-
- - `[:ascii:]`
- The character is 7-bit, i.e. is a single-byte character without
- the top bit set.
-
- - `[:blank:]`
- The character is a blank character
-
- - `[:cntrl:]`
- The character is a control character
-
- - `[:digit:]`
- The character is a decimal digit
-
- - `[:graph:]`
- `[:lower:]`
- The character is a lowercase letter
-
- - `[:print:]`
- `[:punct:]`
- `[:space:]`
- The character is whitespace
-
- - `[:upper:]`
- The character is an uppercase letter
-
- - `[:xdigit:]`
- The character is a hexadecimal digit
-
- Another set of named classes is handled internally by the shell and
- is not sensitive to the locale:
-
- - `[:IDENT:]`
- The character is allowed to form part of a shell identifier,
- such as a parameter name
-
- - `[:IFS:]`
- The character is used as an input field separator, i.e. is
- contained in the `IFS` parameter
-
- - `[:IFSSPACE:]`
- The character is an IFS white space character; see the
- documentation for `IFS` in [Parameters Used By The
- Shell](Parameters.html#Parameters-Used-By-The-Shell).
-
- - `[:INCOMPLETE:]`
- Matches a byte that starts an incomplete multibyte character.
- Note that there may be a sequence of more than one bytes that
- taken together form the prefix of a multibyte character. To test
- for a potentially incomplete byte sequence, use the pattern
- ‘`[[:INCOMPLETE:]]*`’. This will never match a sequence
- starting with a valid multibyte character.
-
- - `[:INVALID:]`
- Matches a byte that does not start a valid multibyte character.
- Note this may be a continuation byte of an incomplete multibyte
- character as any part of a multibyte string consisting of
- invalid and incomplete multibyte characters is treated as single
- bytes.
-
- - `[:WORD:]`
- The character is treated as part of a word; this test is
- sensitive to the value of the `WORDCHARS` 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 ‘`[[:alnum:]]`’. Named character sets can be used
- alongside other types, e.g. ‘`[[:alpha:]0-9]`’.
+?
+Matches any character.
- - `[^`...`]`
- `[!`...`]`
- Like `[`...`]`, except that it matches any character which is not in
- the given set.
+\[...\]
+Matches any of the enclosed characters. Ranges of characters can be
+specified by separating two characters by a ‘-’. A ‘-’ or ‘\]’ may be
+matched by including it as the first character in the list.
There are also several named
+classes of characters, in the form ‘\[:`name`:\]’ 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 ctype(3):
- - `<`\[`x`\]`-`\[`y`\]`>`
- Matches any number in the range `x` to `y`, inclusive. Either of the
- numbers may be omitted to make the range open-ended; hence ‘`<->`’
- matches any number. To match individual digits, the `[`...`]` form
- is more efficient.
-
- Be careful when using other wildcards adjacent to patterns of this
- form; for example, `<0-9>*` will actually match any number
- whatsoever at the start of the string, since the ‘`<0-9>`’ will
- match the first digit, and the ‘`*`’ will match any others. This is
- a trap for the unwary, but is match always succeeds. Expressions
- such as ‘`<0-9>[^[:digit:]]*`’ can be used instead.
+\[:alnum:\]
+The character is alphanumeric
- - `(`...`)`
- Matches the enclosed pattern. This is used for grouping. If the
- `KSH_GLOB` option is set, then a ‘`@`’, ‘`*`’, ‘`+`’, ‘`?`’ or ‘`!`’
- immediately preceding the ‘`(`’ is treated specially, as detailed
- below. The option `SH_GLOB` prevents bare parentheses from being
- used in this way, though the `KSH_GLOB` option is still available.
-
- Note that grouping cannot extend over multiple directories: it is an
- error to have a ‘`/`’ within a group (this only applies for patterns
- used in filename generation). There is one exception: a group of the
- form `(``pat``/)#` appearing as a complete path segment can match a
- sequence of directories. For example, `foo/(a*/)#bar` matches
- `foo/bar`, `foo/any/bar`, `foo/any/anyother/bar`, and so on.
+\[:alpha:\]
+The character is alphabetic
- - `x``|``y`
- Matches either `x` or `y`. This operator has lower precedence than
- any other. The ‘`|`’ character must be within parentheses, to avoid
- interpretation as a pipeline. The alternatives are tried in order
- from left to right.
+\[:ascii:\]
+The character is 7-bit, i.e. is a single-byte character without the top
+bit set.
- - `^``x`
- (Requires `EXTENDED_GLOB` to be set.) Matches anything except the
- pattern `x`. This has a higher precedence than ‘`/`’, so
- ‘`^foo/bar`’ will search directories in ‘`.`’ except ‘`./foo`’
- for a file named ‘`bar`’.
+\[:blank:\]
+The character is a blank character
- - `x``~``y`
- (Requires `EXTENDED_GLOB` to be set.) Match anything that matches
- the pattern `x` but does not match `y`. This has lower precedence
- than any operator except ‘`|`’, so ‘`*/*~foo/bar`’ will search for
- all files in all directories in ‘`.`’ and then exclude ‘`foo/bar`’
- if there was such a match. Multiple patterns can be excluded by
- ‘`foo``~``bar``~``baz`’. In the exclusion pattern (`y`), ‘`/`’ and
- ‘`.`’ are not treated specially the way they usually are in
- globbing.
+\[:cntrl:\]
+The character is a control character
- - `x``#`
- (Requires `EXTENDED_GLOB` to be set.) Matches zero or more
- occurrences of the pattern `x`. This operator has high precedence;
- ‘`12#`’ is equivalent to ‘`1(2#)`’, rather than ‘`(12)#`’. It is
- an error for an unquoted ‘`#`’ to follow something which cannot be
- repeated; this includes an empty string, a pattern already followed
- by ‘`##`’, or parentheses when part of a `KSH_GLOB` pattern (for
- example, ‘`!(``foo``)#`’ is invalid and must be replaced by
- ‘`*(!(``foo``))`’).
+\[:digit:\]
+The character is a decimal digit
- - `x``##`
- (Requires `EXTENDED_GLOB` to be set.) Matches one or more
- occurrences of the pattern `x`. This operator has high precedence;
- ‘`12##`’ is equivalent to ‘`1(2##)`’, rather than ‘`(12)##`’. No
- more than two active ‘`#`’ characters may appear together. (Note the
- potential clash with glob qualifiers in the form ‘`1(2##)`’ which
- should therefore be avoided.)
+\[:graph:\]
+\[:lower:\]
+The character is a lowercase letter
------
+\[:print:\]
+\[:punct:\]
+\[:space:\]
+The character is whitespace
+
+\[:upper:\]
+The character is an uppercase letter
+
+\[:xdigit:\]
+The character is a hexadecimal digit
+
+Another set of named classes is handled internally by the shell and is
+not sensitive to the locale:
+
+\[:IDENT:\]
+The character is allowed to form part of a shell identifier, such as a
+parameter name; this test respects the POSIX_IDENTIFIERS option
+
+\[:IFS:\]
+The character is used as an input field separator, i.e. is contained in
+the IFS parameter
+
+\[:IFSSPACE:\]
+The character is an IFS white space character; see the documentation for
+IFS in [Parameters Used By The
+Shell](Parameters.html#Parameters-Used-By-The-Shell).
+
+\[:INCOMPLETE:\]
+Matches a byte that starts an incomplete multibyte character. Note that
+there may be a sequence of more than one bytes that taken together form
+the prefix of a multibyte character. To test for a potentially
+incomplete byte sequence, use the pattern ‘\[\[:INCOMPLETE:\]\]\*’. This
+will never match a sequence starting with a valid multibyte character.
+
+\[:INVALID:\]
+Matches a byte that does not start a valid multibyte character. Note
+this may be a continuation byte of an incomplete multibyte character as
+any part of a multibyte string consisting of invalid and incomplete
+multibyte characters is treated as single bytes.
+
+\[:WORD:\]
+The character is treated as part of a word; this test is sensitive to
+the value of the WORDCHARS 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 ‘\[\[:alnum:\]\]’. Named character sets can be used alongside
+other types, e.g. ‘\[\[:alpha:\]0-9\]’.
+
+\[^...\]
+\[!...\]
+Like \[...\], except that it matches any character which is not in the
+given set.
+
+\<\[`x`\]-\[`y`\]\>
+Matches any number in the range `x` to `y`, inclusive. Either of the
+numbers may be omitted to make the range open-ended; hence ‘\<->’
+matches any number. To match individual digits, the \[...\] form is more
+efficient.
+
+Be careful when using other wildcards adjacent to patterns of this form;
+for example, \<0-9>\* will actually match any number whatsoever at the
+start of the string, since the ‘\<0-9>’ will match the first digit, and
+the ‘\*’ will match any others. This is a trap for the unwary, but is
+match always succeeds. Expressions such as ‘\<0-9>\[^\[:digit:\]\]\*’
+can be used instead.
+
+(...)
+Matches the enclosed pattern. This is used for grouping. If the KSH_GLOB
+option is set, then a ‘@’, ‘\*’, ‘+’, ‘?’ or ‘!’ immediately preceding
+the ‘(’ is treated specially, as detailed below. The option SH_GLOB
+prevents bare parentheses from being used in this way, though the
+KSH_GLOB option is still available.
+
+Note that grouping cannot extend over multiple directories: it is an
+error to have a ‘/’ within a group (this only applies for patterns used
+in filename generation). There is one exception: a group of the form
+(`pat`/)# appearing as a complete path segment can match a sequence of
+directories. For example, foo/(a\*/)#bar matches foo/bar, foo/any/bar,
+foo/any/anyother/bar, and so on.
+
+`x`\|`y`
+Matches either `x` or `y`. This operator has lower precedence than any
+other. The ‘\|’ character must be within parentheses, to avoid
+interpretation as a pipeline. The alternatives are tried in order from
+left to right.
+
+^`x`
+(Requires EXTENDED_GLOB to be set.) Matches anything except the pattern
+`x`. This has a higher precedence than ‘/’, so ‘^foo/bar’ will search
+directories in ‘.’ except ‘./foo’ for a file named ‘bar’.
+
+`x`\~`y`
+(Requires EXTENDED_GLOB to be set.) Match anything that matches the
+pattern `x` but does not match `y`. This has lower precedence than any
+operator except ‘\|’, so ‘\*/\*\~foo/bar’ will search for all files in
+all directories in ‘.’ and then exclude ‘foo/bar’ if there was such a
+match. Multiple patterns can be excluded by ‘`foo`\~`bar`\~`baz`’. In
+the exclusion pattern (`y`), ‘/’ and ‘.’ are not treated specially the
+way they usually are in globbing.
+
+`x`#
+(Requires EXTENDED_GLOB to be set.) Matches zero or more occurrences of
+the pattern `x`. This operator has high precedence; ‘12#’ is equivalent
+to ‘1(2#)’, rather than ‘(12)#’. It is an error for an unquoted ‘#’ to
+follow something which cannot be repeated; this includes an empty
+string, a pattern already followed by ‘##’, or parentheses when part of
+a KSH_GLOB pattern (for example, ‘!(`foo`)#’ is invalid and must be
+replaced by ‘\*(!(`foo`))’).
+
+`x`##
+(Requires EXTENDED_GLOB to be set.) Matches one or more occurrences of
+the pattern `x`. This operator has high precedence; ‘12##’ is equivalent
+to ‘1(2##)’, rather than ‘(12)##’. No more than two active ‘#’
+characters may appear together. (Note the potential clash with glob
+qualifiers in the form ‘1(2##)’ which should therefore be avoided.)
+
+------------------------------------------------------------------------
@@ -2403,30 +2380,28 @@ of pattern matching, the ‘`/`’ and ‘`.`’ are not treated specially.
-If the `KSH_GLOB` option is set, the effects of parentheses can be
-modified by a preceding ‘`@`’, ‘`*`’, ‘`+`’, ‘`?`’ or ‘`!`’. This
-character need not be unquoted to have special effects, but the ‘`(`’
-must be.
+If the KSH_GLOB option is set, the effects of parentheses can be
+modified by a preceding ‘@’, ‘\*’, ‘+’, ‘?’ or ‘!’. This character need
+not be unquoted to have special effects, but the ‘(’ must be.
- - `@(`...`)`
- Match the pattern in the parentheses. (Like ‘`(`...`)`’.)
+@(...)
+Match the pattern in the parentheses. (Like ‘(...)’.)
- - `*(`...`)`
- Match any number of occurrences. (Like ‘`(`...`)#`’, except that
- recursive directory searching is not supported.)
+\*(...)
+Match any number of occurrences. (Like ‘(...)#’, except that recursive
+directory searching is not supported.)
- - `+(`...`)`
- Match at least one occurrence. (Like ‘`(`...`)##`’, except that
- recursive directory searching is not supported.)
++(...)
+Match at least one occurrence. (Like ‘(...)##’, except that recursive
+directory searching is not supported.)
- - `?(`...`)`
- Match zero or one occurrence. (Like ‘`(|`...`)`’.)
+?(...)
+Match zero or one occurrence. (Like ‘(\|...)’.)
- - `!(`...`)`
- Match anything but the expression in parentheses. (Like
- ‘`(^(`...`))`’.)
+!(...)
+Match anything but the expression in parentheses. (Like ‘(^(...))’.)
------
+------------------------------------------------------------------------
@@ -2434,303 +2409,300 @@ must be.
-The precedence of the operators given above is (highest) ‘`^`’, ‘`/`’,
-‘`~`’, ‘`|`’ (lowest); the remaining operators are simply treated from
-left to right as part of a string, with ‘`#`’ and ‘`##`’ applying to the
-shortest possible preceding unit (i.e. a character, ‘`?`’, ‘`[`...`]`’,
-‘`<`...`>`’, or a parenthesised expression). As mentioned above, a
-‘`/`’ used as a directory separator may not appear inside parentheses,
-while a ‘`|`’ must do so; in patterns used in other contexts than
-filename generation (for example, in `case` statements and tests within
-‘`[[`...`]]`’), a ‘`/`’ is not special; and ‘`/`’ is also not special
-after a ‘`~`’ appearing outside parentheses in a filename pattern.
+The precedence of the operators given above is (highest) ‘^’, ‘/’, ‘\~’,
+‘\|’ (lowest); the remaining operators are simply treated from left to
+right as part of a string, with ‘#’ and ‘##’ applying to the shortest
+possible preceding unit (i.e. a character, ‘?’, ‘\[...\]’, ‘\<...>’, or
+a parenthesised expression). As mentioned above, a ‘/’ used as a
+directory separator may not appear inside parentheses, while a ‘\|’ must
+do so; in patterns used in other contexts than filename generation (for
+example, in case statements and tests within ‘\[\[...\]\]’), a ‘/’ is
+not special; and ‘/’ is also not special after a ‘\~’ appearing outside
+parentheses in a filename pattern.
------
+------------------------------------------------------------------------
### 14.8.4 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 `EXTENDED_GLOB` option. All take the form `(#``X``)` where `X` may
-have one of the following forms:
+the EXTENDED_GLOB option. All take the form (#`X`) where `X` may have
+one of the following forms:
- - `i`
- Case insensitive: upper or lower case characters in the pattern
- match upper or lower case characters.
+i
+Case insensitive: upper or lower case characters in the pattern match
+upper or lower case characters.
- - `l`
- Lower case characters in the pattern match upper or lower case
- characters; upper case characters in the pattern still only match
- upper case characters.
+l
+Lower case characters in the pattern match upper or lower case
+characters; upper case characters in the pattern still only match upper
+case characters.
- - `I`
- Case sensitive: locally negates the effect of `i` or `l` from that
- point on.
-
-
-
+I
+Case sensitive: locally negates the effect of i or l from that point on.
- - `b`
- 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 `$match`, the indices of the beginning of
- the matched parentheses in the array `$mbegin`, and the indices of
- the end in the array `$mend`, 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
- `$mend` and `$mbegin` may be used in subscripts; the `KSH_ARRAYS`
- option is respected. Sets of globbing flags are not considered
- parenthesised groups; only the first nine active parentheses can be
- referenced.
-
- For example,
-
-
-
- ``` example
- foo="a_string_with_a_message"
- if [[ $foo = (a|an)_(#b)(*) ]]; then
- print ${foo[$mbegin[1],$mend[1]]}
- fi
- ```
-
-
-
- prints ‘`string_with_a_message`’. Note that the first set of
- parentheses is before the `(#b)` 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 `${``array``#``pattern``}`, or a global
- substitution, such as `${``param``//``pat``/``repl``}`, 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 `m`
- 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 ‘`#`’ or ‘`##`’. Only the last match of
- the parenthesis is remembered: for example, in ‘`[[ abab =
- (#b)([ab])# ]]`’, only the final ‘`b`’ is stored in `match[1]`. Thus
- extra parentheses may be necessary to match the complete segment:
- for example, use ‘`X((ab|cd)#)Y`’ to match a whole string of either
- ‘`ab`’ or ‘`cd`’ between ‘`X`’ and ‘`Y`’, using the value of
- `$match[1]` rather than `$match[2]`.
-
- 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
- `#` 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.
+
- - `B`
- Deactivate backreferences, negating the effect of the `b` flag from
- that point on.
+b
+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 $match, the indices of the beginning of the matched
+parentheses in the array $mbegin, and the indices of the end in the
+array $mend, 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 $mend and $mbegin may be
+used in subscripts; the KSH_ARRAYS option is respected. Sets of globbing
+flags are not considered parenthesised groups; only the first nine
+active parentheses can be referenced.
- - `c``N``,``M`
- The flag `(#c``N``,``M``)` can be used anywhere that the `#` or `##`
- operators can be used except in the expressions ‘`(*/)#`’ and
- ‘`(*/)##`’ in filename generation, where ‘`/`’ has special
- meaning; it cannot be combined with other globbing flags and a bad
- pattern error occurs if it is misplaced. It is equivalent to the
- form `{``N``,``M``}` in regular expressions. The previous character
- or group is required to match between `N` and `M` times, inclusive.
- The form `(#c``N``)` requires exactly `N` matches; `(#c,``M``)` is
- equivalent to specifying `N` as 0; `(#c``N``,)` specifies that there
- is no maximum limit on the number of matches.
-
-
-
+For example,
- - `m`
- 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 `$MATCH`, `$MBEGIN` and
- `$MEND` 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,
-
-
-
- ``` example
- arr=(veldt jynx grimps waqf zho buck)
- print ${arr//(#m)[aeiou]/${(U)MATCH}}
- ```
-
-
-
- forces all the matches (i.e. all vowels) into uppercase, printing
- ‘`vEldt jynx grImps wAqf zhO bUck`’.
-
- 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.
+
- - `M`
- Deactivate the `m` flag, hence no references to match data will be
- created.
+```zsh
+foo="a_string_with_a_message"
+if [[ $foo = (a|an)_(#b)(*) ]]; then
+ print ${foo[$mbegin[1],$mend[1]]}
+fi
+```
- - `a``num`
- Approximate matching: `num` errors are allowed in the string matched
- by the pattern. The rules for this are described in the next
- subsection.
+
- - `s`, `e`
- Unlike the other flags, these have only a local effect, and each
- must appear on its own: ‘`(#s)`’ and ‘`(#e)`’ are the only valid
- forms. The ‘`(#s)`’ flag succeeds only at the start of the test
- string, and the ‘`(#e)`’ flag succeeds only at the end of the test
- string; they correspond to ‘`^`’ and ‘`$`’ 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,
- ‘`*((#s)|/)test((#e)|/)*`’ matches a path segment ‘`test`’ in
- any of the following strings: `test`, `test/at/start`,
- `at/end/test`, `in/test/middle`.
-
- Another use is in parameter substitution; for example
- ‘`${array/(#s)A*Z(#e)}`’ will remove only elements of an array
- which match the complete pattern ‘`A*Z`’. There are other ways of
- performing many operations of this type, however the combination of
- the substitution operations ‘`/`’ and ‘`//`’ with the ‘`(#s)`’ and
- ‘`(#e)`’ flags provides a single simple and memorable method.
-
- Note that assertions of the form ‘`(^(#s))`’ 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 ‘`(""~(#s))`’ to match a zero-length
- portion of the string not at the start.
+prints ‘string_with_a\_message’. Note that the first set of parentheses
+is before the (#b) and does not create a backreference.
- - `q`
- A ‘`q`’ 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 ‘`(#b)(*).c(#q.)`’ can be used both for globbing and for
- matching against a string. In the former case, the ‘`(#q.)`’ will be
- treated as a glob qualifier and the ‘`(#b)`’ will not be useful,
- while in the latter case the ‘`(#b)`’ is useful for backreferences
- and the ‘`(#q.)`’ will be ignored. Note that colon modifiers in the
- glob qualifiers are also not applied in ordinary pattern matching.
+Backreferences work with all forms of pattern matching other than
+filename generation, but note that when performing matches on an entire
+array, such as ${`array`#`pattern`}, or a global substitution, such as
+${`param`//`pat`/`repl`}, 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 m flag below.
- - `u`
- Respect the current locale in determining the presence of multibyte
- characters in a pattern, provided the shell was compiled with
- `MULTIBYTE_SUPPORT`. This overrides the `MULTIBYTE` option; the
- default behaviour is taken from the option. Compare `U`. (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.)
+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 ‘#’ or ‘##’. Only the last match of the
+parenthesis is remembered: for example, in ‘\[\[ abab = (#b)(\[ab\])#
+\]\]’, only the final ‘b’ is stored in match\[1\]. Thus extra
+parentheses may be necessary to match the complete segment: for example,
+use ‘X((ab\|cd)#)Y’ to match a whole string of either ‘ab’ or ‘cd’
+between ‘X’ and ‘Y’, using the value of $match\[1\] rather than
+$match\[2\].
- - `U`
- All characters are considered to be a single byte long. The opposite
- of `u`. This overrides the `MULTIBYTE` option.
+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 # and matched
+zero times — then the matched string is set to the empty string, and the
+start and end indices are set to -1.
-For example, the test string `fooxx` can be matched by the pattern
-`(#i``)FOOXX`, but not by `(#l``)FOOXX`, `(#i``)FOO``(#I``)XX` or
-`((#i``)FOOX``)X`. The string `(#ia2``)readme` specifies
-case-insensitive matching of `readme` with up to two errors.
+Pattern matching with backreferences is slightly slower than without.
-When using the ksh syntax for grouping both `KSH_GLOB` and
-`EXTENDED_GLOB` must be set and the left parenthesis should be preceded
-by `@`. Note also that the flags do not affect letters inside `[`...`]`
-groups, in other words `(#i``)[a-z]` 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 `(#i``)/foo/bar/...` is potentially
-slow.
+B
+Deactivate backreferences, negating the effect of the b flag from that
+point on.
------
+c`N`,`M`
+The flag (#c`N`,`M`) can be used anywhere that the # or ## operators can
+be used except in the expressions ‘(\*/)#’ and ‘(\*/)##’ in filename
+generation, where ‘/’ has special meaning; it cannot be combined with
+other globbing flags and a bad pattern error occurs if it is misplaced.
+It is equivalent to the form {`N`,`M`} in regular expressions. The
+previous character or group is required to match between `N` and `M`
+times, inclusive. The form (#c`N`) requires exactly N matches; (#c,`M`)
+is equivalent to specifying `N` as 0; (#c`N`,) specifies that there is
+no maximum limit on the number of matches.
+
+
+
+m
+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 $MATCH, $MBEGIN and $MEND 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,
+
+
+
+```zsh
+arr=(veldt jynx grimps waqf zho buck)
+print ${arr//(#m)[aeiou]/${(U)MATCH}}
+```
+
+
+
+forces all the matches (i.e. all vowels) into uppercase, printing ‘vEldt
+jynx grImps wAqf zhO bUck’.
+
+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.
+
+M
+Deactivate the m flag, hence no references to match data will be
+created.
+
+a`num`
+Approximate matching: `num` errors are allowed in the string matched by
+the pattern. The rules for this are described in the next subsection.
+
+s, e
+Unlike the other flags, these have only a local effect, and each must
+appear on its own: ‘(#s)’ and ‘(#e)’ are the only valid forms. The
+‘(#s)’ flag succeeds only at the start of the test string, and the
+‘(#e)’ flag succeeds only at the end of the test string; they correspond
+to ‘^’ and ‘$’ 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, ‘\*((#s)\|/)test((#e)\|/)\*’ matches a path segment ‘test’ in
+any of the following strings: test, test/at/start, at/end/test,
+in/test/middle.
+
+Another use is in parameter substitution; for example
+‘${array/(#s)A\*Z(#e)}’ will remove only elements of an array which
+match the complete pattern ‘A\*Z’. There are other ways of performing
+many operations of this type, however the combination of the
+substitution operations ‘/’ and ‘//’ with the ‘(#s)’ and ‘(#e)’ flags
+provides a single simple and memorable method.
+
+Note that assertions of the form ‘(^(#s))’ 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 ‘(""\~(#s))’ to match a zero-length portion of the string
+not at the start.
+
+q
+A ‘q’ 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
+‘(#b)(\*).c(#q.)’ can be used both for globbing and for matching against
+a string. In the former case, the ‘(#q.)’ will be treated as a glob
+qualifier and the ‘(#b)’ will not be useful, while in the latter case
+the ‘(#b)’ is useful for backreferences and the ‘(#q.)’ will be ignored.
+Note that colon modifiers in the glob qualifiers are also not applied in
+ordinary pattern matching.
+
+u
+Respect the current locale in determining the presence of multibyte
+characters in a pattern, provided the shell was compiled with
+MULTIBYTE_SUPPORT. This overrides the MULTIBYTE option; the default
+behaviour is taken from the option. Compare U. (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.)
+
+U
+All characters are considered to be a single byte long. The opposite
+of u. This overrides the MULTIBYTE option.
+
+For example, the test string fooxx can be matched by the pattern
+(#i)FOOXX, but not by (#l)FOOXX, (#i)FOO(#I)XX or ((#i)FOOX)X. The
+string (#ia2)readme specifies case-insensitive matching of readme with
+up to two errors.
+
+When using the ksh syntax for grouping both KSH_GLOB and EXTENDED_GLOB
+must be set and the left parenthesis should be preceded by @. Note also
+that the flags do not affect letters inside \[...\] groups, in other
+words (#i)\[a-z\] 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
+(#i)/foo/bar/... is potentially slow.
+
+------------------------------------------------------------------------
### 14.8.5 Approximate Matching
+
+
When matching approximately, the shell keeps a count of the errors
-found, which cannot exceed the number specified in the `(#a``num``)`
-flags. Four types of error are recognised:
+found, which cannot exceed the number specified in the (#a`num`) flags.
+Four types of error are recognised:
- - 1\.
- Different characters, as in `fooxbar` and `fooybar`.
+1\.
+Different characters, as in fooxbar and fooybar.
- - 2\.
- Transposition of characters, as in `banana` and `abnana`.
+2\.
+Transposition of characters, as in banana and abnana.
- - 3\.
- A character missing in the target string, as with the pattern `road`
- and target string `rod`.
+3\.
+A character missing in the target string, as with the pattern road and
+target string rod.
- - 4\.
- An extra character appearing in the target string, as with `stove`
- and `strove`.
+4\.
+An extra character appearing in the target string, as with stove and
+strove.
-Thus, the pattern `(#a3``)abcd` matches `dcba`, with the errors
-occurring by using the first rule twice and the second once, grouping
-the string as `[d][cb][a]` and `[a][bc][d]`.
+Thus, the pattern (#a3)abcd matches dcba, with the errors occurring by
+using the first rule twice and the second once, grouping the string as
+\[d\]\[cb\]\[a\] and \[a\]\[bc\]\[d\].
Non-literal parts of the pattern must match exactly, including
-characters in character ranges: hence `(#a1``)???` 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 `?` must match. Other characters
+characters in character ranges: hence (#a1)??? 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 ? must match. Other characters
which must match exactly are initial dots in filenames (unless the
-`GLOB_DOTS` option is set), and all slashes in filenames, so that `a/bc`
-is two errors from `ab/c` (the slash cannot be transposed with another
+GLOB_DOTS option is set), and all slashes in filenames, so that a/bc is
+two errors from ab/c (the slash cannot be transposed with another
character). Similarly, errors are counted separately for non-contiguous
-strings in the pattern, so that `(ab|cd``)ef` is two errors from `aebf`.
+strings in the pattern, so that (ab\|cd)ef is two errors from aebf.
-When using exclusion via the `~` operator, approximate matching is
+When using exclusion via the \~ operator, approximate matching is
treated entirely separately for the excluded part and must be activated
-separately. Thus, `(#a1``)README~READ_ME` matches `READ.ME` but not
-`READ_ME`, as the trailing `READ_ME` is matched without approximation.
-However, `(#a1``)README~(#a1``)READ_ME` does not match any pattern of
-the form `READ``?``ME` as all such forms are now excluded.
+separately. Thus, (#a1)README\~READ_ME matches READ.ME but not READ_ME,
+as the trailing READ_ME is matched without approximation. However,
+(#a1)README\~(#a1)READ_ME does not match any pattern of the form
+READ`?`ME 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, `(#a1``)cat``((#a0``)dog``)fox`
-allows one error in total, which may not occur in the `dog` section, and
-the pattern `(#a1``)cat``(#a0``)dog``(#a1``)fox` 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,
-`(#a1)abc(#a0)xyz` will not match `abcdxyz`, because the error occurs at
-the ‘`x`’, where approximation is turned off.
+delimited by grouping. For example, (#a1)cat((#a0)dog)fox allows one
+error in total, which may not occur in the dog section, and the pattern
+(#a1)cat(#a0)dog(#a1)fox 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, (#a1)abc(#a0)xyz will not match abcdxyz,
+because the error occurs at the ‘x’, where approximation is turned off.
Entire path segments may be matched approximately, so that
-‘`(#a1)/foo/d/is/available/at/the/bar`’ allows one error in any path
-segment. This is much less efficient than without the `(#a1)`, however,
+‘(#a1)/foo/d/is/available/at/the/bar’ allows one error in any path
+segment. This is much less efficient than without the (#a1), however,
since every directory in the path must be scanned for a possible
-approximate match. It is best to place the `(#a1)` after any path
-segments which are known to be correct.
+approximate match. It is best to place the (#a1) after any path segments
+which are known to be correct.
------
+------------------------------------------------------------------------
### 14.8.6 Recursive Globbing
-A pathname component of the form ‘`(``foo``/)#`’ matches a path
-consisting of zero or more directories matching the pattern `foo`.
+
-As a shorthand, ‘`**/`’ is equivalent to ‘`(*/)#`’; note that this
+A pathname component of the form ‘(`foo`/)#’ matches a path consisting
+of zero or more directories matching the pattern `foo`.
+
+As a shorthand, ‘\*\*/’ is equivalent to ‘(\*/)#’; note that this
therefore matches files in the current directory as well as
subdirectories. Thus:
-``` example
+```zsh
ls -ld -- (*/)#bar
```
@@ -2740,26 +2712,26 @@ or
-``` example
+```zsh
ls -ld -- **/bar
```
-does a recursive directory search for files named ‘`bar`’ (potentially
-including the file ‘`bar`’ in the current directory). This form does not
-follow symbolic links; the alternative form ‘`***/`’ does, but is
+does a recursive directory search for files named ‘bar’ (potentially
+including the file ‘bar’ in the current directory). This form does not
+follow symbolic links; the alternative form ‘\*\*\*/’ 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 ‘`*`’
+of globbing within the same path segment; in that case, the ‘\*’
operators revert to their usual effect.
-Even shorter forms are available when the option `GLOB_STAR_SHORT` is
-set. In that case if no `/` immediately follows a `**` or `***` they are
-treated as if both a `/` plus a further `*` are present. Hence:
+Even shorter forms are available when the option GLOB_STAR_SHORT is set.
+In that case if no / immediately follows a \*\* or \*\*\* they are
+treated as if both a / plus a further \* are present. Hence:
-``` example
+```zsh
setopt GLOBSTARSHORT
ls -ld -- **.c
```
@@ -2770,20 +2742,20 @@ is equivalent to
-``` example
+```zsh
ls -ld -- **/*.c
```
------
+------------------------------------------------------------------------
### 14.8.7 Glob Qualifiers
-
-
+
Patterns used for filename generation may end in a list of qualifiers
enclosed in parentheses. The qualifiers specify which filenames that
@@ -2791,362 +2763,380 @@ otherwise match the given pattern will be inserted in the argument list.
-If the option `BARE_GLOB_QUAL` is set, then a trailing set of
-parentheses containing no ‘`|`’ or ‘`(`’ characters (or ‘`~`’ 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 ‘`(^x)`’, can be
-forced to be treated as part of the glob pattern by doubling the
-parentheses, in this case producing ‘`((^x))`’.
+If the option BARE_GLOB_QUAL is set, then a trailing set of parentheses
+containing no ‘\|’ or ‘(’ characters (or ‘\~’ 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 ‘(^x)’, can be forced to be
+treated as part of the glob pattern by doubling the parentheses, in this
+case producing ‘((^x))’.
-If the option `EXTENDED_GLOB` is set, a different syntax for glob
-qualifiers is available, namely ‘`(#q``x``)`’ where `x` is any of the
-same glob qualifiers used in the other format. The qualifiers must still
+If the option EXTENDED_GLOB is set, a different syntax for glob
+qualifiers is available, namely ‘(#q`x`)’ where `x` 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 ‘`|`’, ‘`(`’
-or ‘`~`’ 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 files if both options are set; however, mixed syntax should probably
-be avoided for the sake of clarity. Note that within conditions using
-the ‘`[[`’ form the presence of a parenthesised expression `(#q``...``)`
-at the end of a string indicates that globbing should be performed; the
-expression may include glob qualifiers, but it is also valid if it is
-simply `(#q)`. This does not apply to the right hand side of pattern
-match operators as the syntax already has special significance.
+parentheses contained within it are balanced; appearance of ‘\|’, ‘(’ or
+‘\~’ 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 files if
+both options are set; however, mixed syntax should probably be avoided
+for the sake of clarity. Note that within conditions using the ‘\[\[’
+form the presence of a parenthesised expression (#q`...`) at the end of
+a string indicates that globbing should be performed; the expression may
+include glob qualifiers, but it is also valid if it is simply (#q). This
+does not apply to the right hand side of pattern match operators as the
+syntax already has special significance.
A qualifier may be any one of the following:
- - `/`
- directories
+/
+directories
- - `F`
- ‘full’ (i.e. non-empty) directories. Note that the opposite sense
- `(^F``)` expands to empty directories and all non-directories. Use
- `(/^F``)` for empty directories.
+F
+‘full’ (i.e. non-empty) directories. Note that the opposite sense (^F)
+expands to empty directories and all non-directories. Use (/^F) for
+empty directories.
- - `.`
- plain files
+.
+plain files
- - `@`
- symbolic links
+@
+symbolic links
- - `=`
- sockets
+=
+sockets
- - `p`
- named pipes (FIFOs)
+p
+named pipes (FIFOs)
- - `*`
- `%`
- device files (character or block special)
+\*
+%
+device files (character or block special)
- - `%b`
- block special files
+%b
+block special files
- - `%c`
- character special files
+%c
+character special files
- - `r`
- owner-readable files (0400)
+r
+owner-readable files (0400)
- - `w`
- `x`
- `A`
- group-readable files (0040)
+w
+x
+A
+group-readable files (0040)
- - `I`
- `E`
- `R`
- world-readable files (0004)
+I
+E
+R
+world-readable files (0004)
- - `W`
- `X`
- `s`
- setuid files (04000)
+W
+X
+s
+setuid files (04000)
- - `S`
- setgid files (02000)
+S
+setgid files (02000)
- - `t`
- files with the sticky bit (01000)
+t
+files with the sticky bit (01000)
- - `f``spec`
- files with access rights matching `spec`. This `spec` may be a octal
- number optionally preceded by a ‘`=`’, a ‘`+`’, or a ‘`-`’. If none
- of these characters is given, the behavior is the same as for ‘`=`’.
- The octal number describes the mode bits to be expected, if combined
- with a ‘`=`’, the value given must match the file-modes exactly,
- with a ‘`+`’, at least the bits in the given number must be set in
- the file-modes, and with a ‘`-`’, the bits in the number must not be
- set. Giving a ‘`?`’ 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 ‘`=`’.
-
- If the qualifier ‘`f`’ is followed by any other character anything
- up to the next matching character (‘`[`’, ‘`{`’, and ‘`<`’ match
- ‘`]`’, ‘`}`’, and ‘`>`’ respectively, any other character matches
- itself) is taken as a list of comma-separated `sub-spec`s. Each
- `sub-spec` may be either an octal number as described above or a
- list of any of the characters ‘`u`’, ‘`g`’, ‘`o`’, and ‘`a`’,
- followed by a ‘`=`’, a ‘`+`’, or a ‘`-`’, followed by a list of any
- of the characters ‘`r`’, ‘`w`’, ‘`x`’, ‘`s`’, and ‘`t`’, or an octal
- digit. The first list of characters specify which access rights are
- to be checked. If a ‘`u`’ is given, those for the owner of the file
- are used, if a ‘`g`’ is given, those of the group are checked, a
- ‘`o`’ means to test those of other users, and the ‘`a`’ says to
- test all three groups. The ‘`=`’, ‘`+`’, and ‘`-`’ 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: ‘`r`’ for read access, ‘`w`’
- for write access, ‘`x`’ for the right to execute the file (or to
- search a directory), ‘`s`’ for the setuid and setgid bits, and ‘`t`’
- for the sticky bit.
-
- Thus, ‘`*(f70?)`’ 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 ‘`*(f-100)`’ gives all files for which the owner does not
- have execute permission, and ‘`*(f:gu+w,o-rx:)`’ 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 permission.
+f`spec`
+files with access rights matching `spec`. This `spec` may be a octal
+number optionally preceded by a ‘=’, a ‘+’, or a ‘-’. If none of these
+characters is given, the behavior is the same as for ‘=’. The octal
+number describes the mode bits to be expected, if combined with a ‘=’,
+the value given must match the file-modes exactly, with a ‘+’, at least
+the bits in the given number must be set in the file-modes, and with a
+‘-’, the bits in the number must not be set. Giving a ‘?’ 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 ‘=’.
- - `e``string`
- `+``cmd`
- The `string` 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 ‘`e`’ will be used
- as a separator and anything up to the next matching separator will
- be taken as the `string`; ‘`[`’, ‘`{`’, and ‘`<`’ match ‘`]`’,
- ‘`}`’, and ‘`>`’, respectively, while any other character
- matches itself. Note that expansions must be quoted in the `string`
- to prevent them from being expanded before globbing is done.
- `string` is then executed as shell code. The string `globqual` is
- appended to the array `zsh_eval_context` the duration of execution.
-
-
-
-
- During the execution of `string` the filename currently being tested
- is available in the parameter `REPLY`; the parameter may be altered
- to a string to be inserted into the list instead of the original
- filename. In addition, the parameter `reply` may be set to an array
- or a string, which overrides the value of `REPLY`. 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 ‘`lonely`’.
- Then the expression ‘`*(e:’reply=(${REPLY}{1,2})’:)`’ will cause the
- words ‘`lonely1`’ and ‘`lonely2`’ to be inserted into the command
- line. Note the quoting of `string`.
-
- The form `+``cmd` has the same effect, but no delimiters appear
- around `cmd`. Instead, `cmd` is taken as the longest sequence of
- characters following the `+` that are alphanumeric or underscore.
- Typically `cmd` will be the name of a shell function that contains
- the appropriate test. For example,
-
-
-
- ``` example
- nt() { [[ $REPLY -nt $NTREF ]] }
- NTREF=reffile
- ls -ld -- *(+nt)
- ```
-
-
-
- lists all files in the directory that have been modified more
- recently than `reffile`.
+If the qualifier ‘f’ is followed by any other character anything up to
+the next matching character (‘\[’, ‘{’, and ‘\<’ match ‘\]’, ‘}’, and
+‘>’ respectively, any other character matches itself) is taken as a list
+of comma-separated `sub-spec`s. Each `sub-spec` may be either an octal
+number as described above or a list of any of the characters ‘u’, ‘g’,
+‘o’, and ‘a’, followed by a ‘=’, a ‘+’, or a ‘-’, followed by a list of
+any of the characters ‘r’, ‘w’, ‘x’, ‘s’, and ‘t’, or an octal digit.
+The first list of characters specify which access rights are to be
+checked. If a ‘u’ is given, those for the owner of the file are used, if
+a ‘g’ is given, those of the group are checked, a ‘o’ means to test
+those of other users, and the ‘a’ says to test all three groups. The
+‘=’, ‘+’, and ‘-’ 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: ‘r’
+for read access, ‘w’ for write access, ‘x’ for the right to execute the
+file (or to search a directory), ‘s’ for the setuid and setgid bits, and
+‘t’ for the sticky bit.
- - `d``dev`
- files on the device `dev`
+Thus, ‘\*(f70?)’ 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
+‘\*(f-100)’ gives all files for which the owner does not have execute
+permission, and ‘\*(f:gu+w,o-rx:)’ 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 permission.
- - `l`\[`-`|`+`\]`ct`
- files having a link count less than `ct` (`-`), greater than `ct`
- (`+`), or equal to `ct`
+e`string`
++`cmd`
+The `string` 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).
- - `U`
- files owned by the effective user ID
+In the first form, the first character after the ‘e’ will be used as a
+separator and anything up to the next matching separator will be taken
+as the `string`; ‘\[’, ‘{’, and ‘\<’ match ‘\]’, ‘}’, and ‘>’,
+respectively, while any other character matches itself. Note that
+expansions must be quoted in the `string` to prevent them from being
+expanded before globbing is done. `string` is then executed as shell
+code. The string globqual is appended to the array zsh_eval_context the
+duration of execution.
- - `G`
- files owned by the effective group ID
+
- - `u``id`
- files owned by user ID `id` if that is a number. Otherwise, `id`
- specifies a user name: the character after the ‘`u`’ 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
- ‘`[`’, ‘`{`’, and ‘`<`’ match the final separators ‘`]`’, ‘`}`’,
- and ‘`>`’, respectively; any other character matches itself. The
- selected files are those owned by this user. For example, ‘`u:foo:`’
- or ‘`u[foo]`’ selects files owned by user ‘`foo`’.
+During the execution of `string` the filename currently being tested is
+available in the parameter REPLY; the parameter may be altered to a
+string to be inserted into the list instead of the original filename. In
+addition, the parameter reply may be set to an array or a string, which
+overrides the value of REPLY. If set to an array, the latter is inserted
+into the command line word by word.
- - `g``id`
- like `u``id` but with group IDs or names
+For example, suppose a directory contains a single file ‘lonely’. Then
+the expression ‘\*(e:’reply=(${REPLY}{1,2})’:)’ will cause the words
+‘lonely1’ and ‘lonely2’ to be inserted into the command line. Note the
+quoting of `string`.
- - `a`\[`Mwhms`\]\[`-`|`+`\]`n`
- files accessed exactly `n` days ago. Files accessed within the last
- `n` days are selected using a negative value for `n` (`-``n`). Files
- accessed more than `n` days ago are selected by a positive `n` value
- (`+``n`). Optional unit specifiers ‘`M`’, ‘`w`’, ‘`h`’, ‘`m`’ or
- ‘`s`’ (e.g. ‘`ah5`’) cause the check to be performed with months
- (of 30 days), weeks, hours, minutes or seconds instead of days,
- respectively. An explicit ‘`d`’ for days is also allowed.
-
- 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, ‘`echo *(ah-5)`’ would echo files accessed
- within the last five hours, while ‘`echo *(ah+5)`’ would echo files
- accessed at least six hours ago, as times strictly between five and
- six hours are treated as five hours.
-
- - `m`\[`Mwhms`\]\[`-`|`+`\]`n`
- like the file access qualifier, except that it uses the file
- modification time.
-
- - `c`\[`Mwhms`\]\[`-`|`+`\]`n`
- like the file access qualifier, except that it uses the file inode
- change time.
-
- - `L`\[`+`|`-`\]`n`
- files less than `n` bytes (`-`), more than `n` bytes (`+`), or
- exactly `n` bytes in length.
-
- If this flag is directly followed by a *size specifier* ‘`k`’
- (‘`K`’), ‘`m`’ (‘`M`’), or ‘`p`’ (‘`P`’) (e.g. ‘`Lk-50`’) the
- check is performed with kilobytes, megabytes, or blocks (of 512
- bytes) instead. (On some systems additional specifiers are available
- for gigabytes, ‘`g`’ or ‘`G`’, and terabytes, ‘`t`’ or ‘`T`’.) If a
- size specifier is used 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 ‘`*(Lm1)`’ 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
- ‘`*(Lm-1)`’ 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
-
- - `M`
- sets the `MARK_DIRS` option for the current pattern
-
-
- - `T`
- appends a trailing qualifier mark to the filenames, analogous to the
- `LIST_TYPES` option, for the current pattern (overrides `M`)
-
- - `N`
- sets the `NULL_GLOB` option for the current pattern
-
-
- - `D`
- sets the `GLOB_DOTS` option for the current pattern
-
-
- - `n`
- sets the `NUMERIC_GLOB_SORT` option for the current pattern
-
-
- - `Y``n`
- enables short-circuit mode: the pattern will expand to at most `n`
- filenames. If more than `n` matches exist, only the first `n`
- matches in directory traversal order will be considered.
-
- Implies `oN` when no `o``c` qualifier is used.
-
- - `o``c`
- specifies how the names of the files should be sorted. If `c` is `n`
- they are sorted by name; if it is `L` they are sorted depending on
- the size (length) of the files; if `l` they are sorted by the number
- of links; if `a`, `m`, or `c` they are sorted by the time of the
- last access, modification, or inode change respectively; if `d`,
- 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 ‘`odon`’ to sort on names for files within the
- same directory; if `N`, no sorting is performed. Note that `a`, `m`,
- and `c` compare the age against the current time, hence the first
- name in the list is the youngest file. Also note that the modifiers
- `^` and `-` are used, so ‘`*(^-oL)`’ gives a list of all files
- sorted by file size in descending order, following any symbolic
- links. Unless `oN` is used, multiple order specifiers may occur to
- resolve ties.
-
- The default sorting is `n` (by name) unless the `Y` glob qualifier
- is used, in which case it is `N` (unsorted).
-
- `oe` and `o+` are special cases; they are each followed by shell
- code, delimited as for the `e` glob qualifier and the `+` glob
- qualifier respectively (see above). The code is executed for each
- matched file with the parameter `REPLY` set to the name of the file
- on entry and `globsort` appended to `zsh_eval_context`. The code
- should modify the parameter `REPLY` 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, `oe` and `o+`
- may be repeated, but note that the maximum number of sort operators
- of any kind that may appear in any glob expression is 12.
-
- - `O``c`
- like ‘`o`’, but sorts in descending order; i.e. ‘`*(^oc)`’ is the
- same as ‘`*(Oc)`’ and ‘`*(^Oc)`’ is the same as ‘`*(oc)`’; ‘`Od`’
- puts files in the current directory before those in subdirectories
- at each level of the search.
-
- - `[``beg`\[`,``end`\]`]`
- specifies which of the matched filenames should be included in the
- returned list. The syntax is the same as for array subscripts. `beg`
- and the optional `end` may be mathematical expressions. As in
- parameter subscripting they may be negative to make them count from
- the last match backward. E.g.: ‘`*(-OL[1,3])`’ gives a list of the
- names of the three largest files.
-
- - `P``string`
- The `string` will be prepended to each glob match as a separate
- word. `string` is delimited in the same way as arguments to the `e`
- 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 ‘`*(P:-f:)`’
- produces the command line arguments ‘`-f` `file1` `-f` `file2` ...’
-
- If the modifier `^` is active, then `string` will be appended
- instead of prepended. Prepending and appending is done independently
- so both can be used on the same glob expression; for example by
- writing ‘`*(P:foo:^P:bar:^P:baz:)`’ which produces the command line
- arguments ‘`foo` `baz` `file1` `bar` ...’
-
-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 ‘`M`’, ‘`T`’,
-‘`N`’, ‘`D`’, ‘`n`’, ‘`o`’, ‘`O`’ and the subscripts given in brackets
-(‘`[``...``]`’).
-
-If a ‘`:`’ appears in a qualifier list, the remainder of the expression
-in parenthesis is interpreted as a modifier (see [Modifiers](#Modifiers)
-in [History Expansion](#History-Expansion)). Each modifier must be
-introduced by a separate ‘`:`’. 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 ‘`(:``...``)`’
-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 `NULL_GLOB`.
-Thus:
+The form +`cmd` has the same effect, but no delimiters appear around
+`cmd`. Instead, `cmd` is taken as the longest sequence of characters
+following the + that are alphanumeric or underscore. Typically `cmd`
+will be the name of a shell function that contains the appropriate test.
+For example,
-``` example
+```zsh
+nt() { [[ $REPLY -nt $NTREF ]] }
+NTREF=reffile
+ls -ld -- *(+nt)
+```
+
+
+
+lists all files in the directory that have been modified more recently
+than reffile.
+
+d`dev`
+files on the device `dev`
+
+l\[-\|+\]`ct`
+files having a link count less than `ct` (-), greater than `ct` (+), or
+equal to `ct`
+
+U
+files owned by the effective user ID
+
+G
+files owned by the effective group ID
+
+u`id`
+files owned by user ID `id` if that is a number. Otherwise, `id`
+specifies a user name: the character after the ‘u’ 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 ‘\[’, ‘{’, and ‘\<’
+match the final separators ‘\]’, ‘}’, and ‘>’, respectively; any other
+character matches itself. The selected files are those owned by this
+user. For example, ‘u:foo:’ or ‘u\[foo\]’ selects files owned by user
+‘foo’.
+
+g`id`
+like u`id` but with group IDs or names
+
+a\[Mwhms\]\[-\|+\]`n`
+files accessed exactly `n` days ago. Files accessed within the last `n`
+days are selected using a negative value for `n` (-`n`). Files accessed
+more than `n` days ago are selected by a positive `n` value (+`n`).
+Optional unit specifiers ‘M’, ‘w’, ‘h’, ‘m’ or ‘s’ (e.g. ‘ah5’) cause
+the check to be performed with months (of 30 days), weeks, hours,
+minutes or seconds instead of days, respectively. An explicit ‘d’ for
+days is also allowed.
+
+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, ‘echo \*(ah-5)’ would echo files accessed within the last five
+hours, while ‘echo \*(ah+5)’ would echo files accessed at least six
+hours ago, as times strictly between five and six hours are treated as
+five hours.
+
+m\[Mwhms\]\[-\|+\]`n`
+like the file access qualifier, except that it uses the file
+modification time.
+
+c\[Mwhms\]\[-\|+\]`n`
+like the file access qualifier, except that it uses the file inode
+change time.
+
+L\[+\|-\]`n`
+files less than `n` bytes (-), more than `n` bytes (+), or exactly `n`
+bytes in length.
+
+If this flag is directly followed by a *size specifier* ‘k’ (‘K’), ‘m’
+(‘M’), or ‘p’ (‘P’) (e.g. ‘Lk-50’) the check is performed with
+kilobytes, megabytes, or blocks (of 512 bytes) instead. (On some systems
+additional specifiers are available for gigabytes, ‘g’ or ‘G’, and
+terabytes, ‘t’ or ‘T’.) If a size specifier is used 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 ‘\*(Lm1)’ 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 ‘\*(Lm-1)’ 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, if any; any symbolic link for
+whose target the ‘stat’ system call fails (whatever the cause of the
+failure) is treated as a file in its own right
+
+M
+sets the MARK_DIRS option for the current pattern
+
+T
+appends a trailing qualifier mark to the filenames, analogous to the
+LIST_TYPES option, for the current pattern (overrides M)
+
+N
+sets the NULL_GLOB option for the current pattern
+
+D
+sets the GLOB_DOTS option for the current pattern
+
+n
+sets the NUMERIC_GLOB_SORT option for the current pattern
+
+Y`n`
+enables short-circuit mode: the pattern will expand to at most `n`
+filenames. If more than `n` matches exist, only the first `n` matches in
+directory traversal order will be considered.
+
+Implies oN when no o`c` qualifier is used.
+
+o`c`
+specifies how the names of the files should be sorted. The following
+values of `c` sort in the following ways:
+
+n
+By name.
+
+L
+By the size (length) of the files.
+
+l
+By number of links.
+
+a
+By time of last access, youngest first.
+
+m
+By time of last modification, youngest first.
+
+c
+By time of last inode change, youngest first.
+
+d
+By directories: 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 ‘odon’ to sort on names for files
+within the same directory.
+
+N
+No sorting is performed.
+
+e`string`
++`cmd`
+Sort by shell code (see below).
+
+Note that the modifiers ^ and - are used, so ‘\*(^-oL)’ gives a list of
+all files sorted by file size in descending order, following any
+symbolic links. Unless oN is used, multiple order specifiers may occur
+to resolve ties.
+
+The default sorting is n (by name) unless the Y glob qualifier is used,
+in which case it is N (unsorted).
+
+oe and o+ are special cases; they are each followed by shell code,
+delimited as for the e glob qualifier and the + glob qualifier
+respectively (see above). The code is executed for each matched file
+with the parameter REPLY set to the name of the file on entry and
+globsort appended to zsh_eval_context. The code should modify the
+parameter REPLY 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, oe and o+ may be repeated, but note that the
+maximum number of sort operators of any kind that may appear in any glob
+expression is 12.
+
+O`c`
+like ‘o’, but sorts in descending order; i.e. ‘\*(^o`c`)’ is the same as
+‘\*(O`c`)’ and ‘\*(^O`c`)’ is the same as ‘\*(o`c`)’; ‘Od’ puts files in
+the current directory before those in subdirectories at each level of
+the search.
+
+\[`beg`\[,`end`\]\]
+specifies which of the matched filenames should be included in the
+returned list. The syntax is the same as for array subscripts. `beg` and
+the optional `end` may be mathematical expressions. As in parameter
+subscripting they may be negative to make them count from the last match
+backward. E.g.: ‘\*(-OL\[1,3\])’ gives a list of the names of the three
+largest files.
+
+P`string`
+The `string` will be prepended to each glob match as a separate word.
+`string` is delimited in the same way as arguments to the e 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 ‘\*(P:-f:)’ produces the command
+line arguments ‘-f `file1` -f `file2` ...’
+
+If the modifier ^ is active, then `string` will be appended instead of
+prepended. Prepending and appending is done independently so both can be
+used on the same glob expression; for example by writing
+‘\*(P:foo:^P:bar:^P:baz:)’ which produces the command line arguments
+‘foo baz `file1` bar ...’
+
+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 ‘M’, ‘T’, ‘N’, ‘D’, ‘n’,
+‘o’, ‘O’ and the subscripts given in brackets (‘\[`...`\]’).
+
+If a ‘:’ appears in a qualifier list, the remainder of the expression in
+parenthesis is interpreted as a modifier (see [Modifiers](#Modifiers) in
+[History Expansion](#History-Expansion)). Each modifier must be
+introduced by a separate ‘:’. 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 ‘(:`...`)’ 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 NULL_GLOB. Thus:
+
+
+
+```zsh
ls -ld -- *(-/)
```
@@ -3156,7 +3146,7 @@ lists all directories and symbolic links that point to directories, and
-``` example
+```zsh
ls -ld -- *(-@)
```
@@ -3166,7 +3156,7 @@ lists all broken symbolic links, and
-``` example
+```zsh
ls -ld -- *(%W)
```
@@ -3174,7 +3164,7 @@ ls -ld -- *(%W)
-``` example
+```zsh
ls -ld -- *(W,X)
```
@@ -3184,43 +3174,43 @@ lists all files in the current directory that are
-``` example
+```zsh
print -rC1 /tmp/foo*(u0^@:t)
```
outputs the basename of all root-owned files beginning with the string
-‘`foo`’ in `/tmp`, ignoring symlinks, and
+‘foo’ in /tmp, ignoring symlinks, and
-``` example
+```zsh
ls -ld -- *.*~(lex|parse).[ch](^D^l1)
```
lists all files having a link count of one whose names contain a dot
-(but not those starting with a dot, since `GLOB_DOTS` is explicitly
-switched off) except for `lex.c`, `lex.h`, `parse.c` and `parse.h`.
+(but not those starting with a dot, since GLOB_DOTS is explicitly
+switched off) except for lex.c, lex.h, parse.c and parse.h.
-``` example
+```zsh
print -rC1 b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/)
```
demonstrates how colon modifiers and other qualifiers may be chained
-together. The ordinary qualifier ‘`.`’ is applied first, then the colon
-modifiers in order from left to right. So if `EXTENDED_GLOB` is set and
-the base pattern matches the regular file `builtin.pro`, the shell will
-print ‘`shmiltin.shmo`’.
+together. The ordinary qualifier ‘.’ is applied first, then the colon
+modifiers in order from left to right. So if EXTENDED_GLOB is set and
+the base pattern matches the regular file builtin.pro, the shell will
+print ‘shmiltin.shmo’.
------
+------------------------------------------------------------------------
-This document was generated on *February 15, 2020* using
-[*texi2html 5.0*](http://www.nongnu.org/texi2html/).
-Zsh version 5.8, released on February 14, 2020.
+This document was generated on *May 14, 2022* using [*texi2html
+5.0*](http://www.nongnu.org/texi2html/).
+Zsh version 5.9, released on May 14, 2022.
diff --git a/zsh_manual/src/Files.md b/zsh_manual/src/Files.md
index 00b9ca0..814265a 100644
--- a/zsh_manual/src/Files.md
+++ b/zsh_manual/src/Files.md
@@ -8,109 +8,106 @@
-
+
# 5 Files
------
+------------------------------------------------------------------------
## 5.1 Startup/Shutdown Files
-
-
-
-
-
-
-
-
-
-
+
-Commands are first read from `/etc/zshenv`; this cannot be overridden.
-Subsequent behaviour is modified by the `RCS` and `GLOBAL_RCS` options;
-the former affects all startup files, while the second only affects
-global startup files (those shown here with an path starting with a
-`/`). If one of the options is unset at any point, any subsequent
-startup file(s) of the corresponding type will not be read. It is also
-possible for a file in `$ZDOTDIR` to re-enable `GLOBAL_RCS`. Both `RCS`
-and `GLOBAL_RCS` are set by default.
+Commands are first read from /etc/zshenv; this cannot be overridden.
+Subsequent behaviour is modified by the RCS and GLOBAL_RCS options; the
+former affects all startup files, while the second only affects global
+startup files (those shown here with an path starting with a /). If one
+of the options is unset at any point, any subsequent startup file(s) of
+the corresponding type will not be read. It is also possible for a file
+in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and GLOBAL_RCS are set by
+default.
-Commands are then read from `$ZDOTDIR/.zshenv`.
-
-
If the shell is a login shell,
-commands are read from `/etc/zprofile` and then `$ZDOTDIR/.zprofile`.
-
Then, if the shell is interactive,
-commands are read from `/etc/zshrc` and then `$ZDOTDIR/.zshrc`.
-
Finally, if the shell is a login shell,
-`/etc/zlogin` and `$ZDOTDIR/.zlogin` are read.
+Commands are then read from $ZDOTDIR/.zshenv.
+If the shell is a login shell, commands are read from /etc/zprofile and
+then $ZDOTDIR/.zprofile.
Then, if the
+shell is interactive, commands are read from /etc/zshrc and then
+$ZDOTDIR/.zshrc.
Finally, if the shell
+is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
-When a login shell exits, the files `$ZDOTDIR/.zlogout` and then
-`/etc/zlogout` are read. This happens with either an explicit exit via
-the `exit` or `logout` commands, or an implicit exit by reading
-end-of-file from the terminal. However, if the shell terminates due to
-`exec`’ing another process, the logout files are not read. These are
-also affected by the `RCS` and `GLOBAL_RCS` options. Note also that the
-`RCS` option affects the saving of history files, i.e. if `RCS` is unset
-when the shell exits, no history file will be saved.
+When a login shell exits, the files $ZDOTDIR/.zlogout and then
+/etc/zlogout are read. This happens with either an explicit exit via the
+exit or logout commands, or an implicit exit by reading end-of-file from
+the terminal. However, if the shell terminates due to exec’ing another
+process, the logout files are not read. These are also affected by the
+RCS and GLOBAL_RCS options. Note also that the RCS option affects the
+saving of history files, i.e. if RCS is unset when the shell exits, no
+history file will be saved.
-If `ZDOTDIR` is unset, `HOME` is used instead. Files listed above as
-being in `/etc` may be in another directory, depending on the
-installation.
+If ZDOTDIR is unset, HOME is used instead. Files listed above as being
+in /etc may be in another directory, depending on the installation.
-As `/etc/zshenv` is run for all instances of zsh, it is important that
-it be kept as small as possible. In particular, it is a good idea to put
+As /etc/zshenv is run for all instances of zsh, it is important that it
+be kept as small as possible. In particular, it is a good idea to put
code that does not need to be run for every single shell behind a test
-of the form ‘`if [[ -o rcs ]]; then ...`’ so that it will not be
-executed when zsh is invoked with the ‘`-f`’ option.
+of the form ‘if \[\[ -o rcs \]\]; then ...’ so that it will not be
+executed when zsh is invoked with the ‘-f’ option.
------
+------------------------------------------------------------------------
-
+
## 5.2 Files
-`$ZDOTDIR/.zshenv`
+$ZDOTDIR/.zshenv
-`$ZDOTDIR/.zprofile`
+$ZDOTDIR/.zprofile
-`$ZDOTDIR/.zshrc`
+$ZDOTDIR/.zshrc
-`$ZDOTDIR/.zlogin`
+$ZDOTDIR/.zlogin
-`$ZDOTDIR/.zlogout`
+$ZDOTDIR/.zlogout
-`${TMPPREFIX}*` (default is /tmp/zsh\*)
+${TMPPREFIX}\* (default is /tmp/zsh\*)
-`/etc/zshenv`
+/etc/zshenv
-`/etc/zprofile`
+/etc/zprofile
-`/etc/zshrc`
+/etc/zshrc
-`/etc/zlogin`
+/etc/zlogin
-`/etc/zlogout` (installation-specific - `/etc` is the default)
+/etc/zlogout (installation-specific - /etc is the default)
-Any of these files may be pre-compiled with the `zcompile` builtin
-command ([Shell Builtin
+Any of these files may be pre-compiled with the zcompile builtin command
+([Shell Builtin
Commands](Shell-Builtin-Commands.html#Shell-Builtin-Commands)). If a
-compiled file exists (named for the original file plus the `.zwc`
+compiled file exists (named for the original file plus the .zwc
extension) and it is newer than the original file, the compiled file
will be used instead.
------
+------------------------------------------------------------------------
-This document was generated on *February 15, 2020* using
-[*texi2html 5.0*](http://www.nongnu.org/texi2html/).
-Zsh version 5.8, released on February 14, 2020.
+This document was generated on *May 14, 2022* using [*texi2html
+5.0*](http://www.nongnu.org/texi2html/).
+Zsh version 5.9, released on May 14, 2022.
diff --git a/zsh_manual/src/Functions.md b/zsh_manual/src/Functions.md
index 20afb3d..6cbd872 100644
--- a/zsh_manual/src/Functions.md
+++ b/zsh_manual/src/Functions.md
@@ -11,55 +11,55 @@
-
+
# 9 Functions
-
-
+
-Shell functions are defined with the `function` reserved word or the
-special syntax ‘`funcname` `()`’. Shell functions are read in and stored
+Shell functions are defined with the function reserved word or the
+special syntax ‘`funcname` ()’. Shell functions are read in and stored
internally. Alias names are resolved when the function is read.
Functions are executed like commands with the arguments passed as
positional parameters. (See [Command
Execution](Command-Execution.html#Command-Execution).)
Functions execute in the same process as the caller and share all files
-and present working directory with the caller. A trap on `EXIT` set
-inside a function is executed after the function completes in the
-environment of the caller.
+and present working directory with the caller. A trap on EXIT set inside
+a function is executed after the function completes in the environment
+of the caller.
-The `return` builtin is used to return from function calls.
+The return builtin is used to return from function calls.
-Function identifiers can be listed with the `functions` builtin.
-
Functions can be
-undefined with the `unfunction` builtin.
+Function identifiers can be listed with the functions builtin.
Functions can be undefined
+with the unfunction builtin.
------
+------------------------------------------------------------------------
## 9.1 Autoloading Functions
-
-
-
-
+
-A function can be marked as *undefined* using the `autoload` builtin (or
-‘`functions -u`’ or ‘`typeset -fu`’). Such a function has no body. When
-the function is first executed, the shell searches for its definition
-using the elements of the `fpath` variable. Thus to define functions for
+A function can be marked as *undefined* using the autoload builtin (or
+‘functions -u’ or ‘typeset -fu’). Such a function has no body. When the
+function is first executed, the shell searches for its definition using
+the elements of the fpath variable. Thus to define functions for
autoloading, a typical sequence is:
-``` example
+```zsh
fpath=(~/myfuncs $fpath)
autoload myfunc1 myfunc2 ...
```
@@ -67,62 +67,60 @@ autoload myfunc1 myfunc2 ...
The usual alias expansion during reading will be suppressed if the
-`autoload` builtin or its equivalent is given the option `-U`. This is
+autoload builtin or its equivalent is given the option -U. This is
recommended for the use of functions supplied with the zsh distribution.
Note that for functions
-precompiled with the `zcompile` builtin command the flag `-U` must be
-provided when the `.zwc` file is created, as the corresponding
-information is compiled into the latter.
+precompiled with the zcompile builtin command the flag -U must be
+provided when the .zwc file is created, as the corresponding information
+is compiled into the latter.
-For each `element` in `fpath`, the shell looks for three possible files,
+For each `element` in fpath, the shell looks for three possible files,
the newest of which is used to load the definition for the function:
- - `element``.zwc`
- A file created with the `zcompile` builtin command, which is
- expected to contain the definitions for all functions in the
- directory named `element`. The file is treated in the same manner as
- a directory containing files for functions and is searched for the
- definition of the function. If the definition is not found, the
- search for a definition proceeds with the other two possibilities
- described below.
-
- If `element` already includes a `.zwc` extension (i.e. the extension
- was explicitly given by the user), `element` is searched for the
- definition of the function without comparing its age to that of
- other files; in fact, there does not need to be any directory named
- `element` without the suffix. Thus including an element such as
- ‘`/usr/local/funcs.zwc`’ in `fpath` will speed up the search for
- functions, with the disadvantage that functions included must be
- explicitly recompiled by hand before the shell notices any changes.
+`element`.zwc
+A file created with the zcompile builtin command, which is expected to
+contain the definitions for all functions in the directory named
+`element`. The file is treated in the same manner as a directory
+containing files for functions and is searched for the definition of the
+function. If the definition is not found, the search for a definition
+proceeds with the other two possibilities described below.
- - `element``/``function``.zwc`
- A file created with `zcompile`, which is expected to contain the
- definition for `function`. It may include other function definitions
- as well, but those are neither loaded nor executed; a file found in
- this way is searched *only* for the definition of `function`.
+If `element` already includes a .zwc extension (i.e. the extension was
+explicitly given by the user), `element` is searched for the definition
+of the function without comparing its age to that of other files; in
+fact, there does not need to be any directory named `element` without
+the suffix. Thus including an element such as ‘/usr/local/funcs.zwc’ in
+fpath will speed up the search for functions, with the disadvantage that
+functions included must be explicitly recompiled by hand before the
+shell notices any changes.
- - `element``/``function`
- A file of zsh command text, taken to be the definition for
- `function`.
+`element`/`function`.zwc
+A file created with zcompile, which is expected to contain the
+definition for `function`. It may include other function definitions as
+well, but those are neither loaded nor executed; a file found in this
+way is searched *only* for the definition of `function`.
+
+`element`/`function`
+A file of zsh command text, taken to be the definition for `function`.
In summary, the order of searching is, first, in the *parents of*
-directories in `fpath` for the newer of either a compiled directory or a
-directory in `fpath`; second, if more than one of these contains a
-definition for the function that is sought, the leftmost in the `fpath`
-is chosen; and third, within a directory, the newer of either a compiled
+directories in fpath for the newer of either a compiled directory or a
+directory in fpath; second, if more than one of these contains a
+definition for the function that is sought, the leftmost in the fpath is
+chosen; and third, within a directory, the newer of either a compiled
function or an ordinary function definition is used.
-If the `KSH_AUTOLOAD` option is set, or the file contains only a simple
+If the KSH_AUTOLOAD option is set, or the file contains only a simple
definition of the function, the file’s contents will be executed. This
will normally define the function in question, but may also perform
initialization, which is executed in the context of the function
execution, and may therefore define local parameters. It is an error if
the function is not defined by loading the file.
-Otherwise, the function body (with no surrounding ‘`funcname``()
-{``...``}`’) is taken to be the complete contents of the file. This
+Otherwise, the function body (with no surrounding ‘`funcname`()
+{`...`}’) is taken to be the complete contents of the file. This
processing of the file results in the function being re-defined, the
function itself is not re-executed. To force the shell to perform
initialization and then call the function defined, the file should
@@ -131,31 +129,31 @@ addition to a complete function definition (which will be retained for
subsequent calls to the function), and a call to the shell function,
including any arguments, at the end.
-For example, suppose the autoload file `func` contains
+For example, suppose the autoload file func contains
-``` example
+```zsh
func() { print This is func; }
print func is initialized
```
-then ‘`func; func`’ with `KSH_AUTOLOAD` set will produce both messages
-on the first call, but only the message ‘`This is func`’ on the second
-and subsequent calls. Without `KSH_AUTOLOAD` set, it will produce the
+then ‘func; func’ with KSH_AUTOLOAD set will produce both messages on
+the first call, but only the message ‘This is func’ on the second and
+subsequent calls. Without KSH_AUTOLOAD set, it will produce the
initialization message on the first call, and the other message on the
second and subsequent calls.
It is also possible to create a function that is not marked as
-autoloaded, but which loads its own definition by searching `fpath`, by
-using ‘`autoload -X`’ within a shell function. For example, the
-following are equivalent:
+autoloaded, but which loads its own definition by searching fpath, by
+using ‘autoload -X’ within a shell function. For example, the following
+are equivalent:
-``` example
+```zsh
myfunc() {
autoload -X
}
@@ -168,7 +166,7 @@ and
-``` example
+```zsh
unfunction myfunc # if myfunc was defined
autoload myfunc
myfunc args...
@@ -176,53 +174,52 @@ myfunc args...
-In fact, the `functions` command outputs ‘`builtin autoload -X`’ as the
-body of an autoloaded function. This is done so that
+In fact, the functions command outputs ‘builtin autoload -X’ as the body
+of an autoloaded function. This is done so that
-``` example
+```zsh
eval "$(functions)"
```
produces a reasonable result. A true autoloaded function can be
-identified by the presence of the comment ‘`# undefined`’ in the body,
+identified by the presence of the comment ‘# undefined’ in the body,
because all comments are discarded from defined functions.
-To load the definition of an autoloaded function `myfunc` without
-executing `myfunc`, use:
+To load the definition of an autoloaded function myfunc without
+executing myfunc, use:
-``` example
+```zsh
autoload +X myfunc
```
------
+------------------------------------------------------------------------
## 9.2 Anonymous Functions
-
-
+
If no name is given for a function, it is ‘anonymous’ and is handled
-specially. Either form of function definition may be used: a ‘`()`’ with
-no preceding name, or a ‘`function`’ with an immediately following open
+specially. Either form of function definition may be used: a ‘()’ with
+no preceding name, or a ‘function’ with an immediately following open
brace. The function is executed immediately at the point of definition
-and is not stored for future use. The function name is set to
-‘`(anon)`’.
+and is not stored for future use. The function name is set to ‘(anon)’.
Arguments to the function may be specified as words following the
closing brace defining the function, hence if there are none no
-arguments (other than `$0`) are set. This is a difference from the way
+arguments (other than $0) are set. This is a difference from the way
other functions are parsed: normal function definitions may be followed
-by certain keywords such as ‘`else`’ or ‘`fi`’, which will be treated as
+by certain keywords such as ‘else’ or ‘fi’, which will be treated as
arguments to anonymous functions, so that a newline or semicolon is
needed to force keyword interpretation.
@@ -240,7 +237,7 @@ For example,
-``` example
+```zsh
variable=outside
function {
local variable=inside
@@ -255,7 +252,7 @@ outputs the following:
-``` example
+```zsh
I am inside with arguments this and that
I am outside
```
@@ -263,11 +260,11 @@ I am outside
Note that function definitions with arguments that expand to nothing,
-for example ‘` name=; function $name { ``...`` } `’, are not treated
-as anonymous functions. Instead, they are treated as normal function
+for example ‘name=; function $name { `...` }’, are not treated as
+anonymous functions. Instead, they are treated as normal function
definitions where the definition is silently discarded.
------
+------------------------------------------------------------------------
@@ -275,63 +272,63 @@ definitions where the definition is silently discarded.
Certain functions, if defined, have special meaning to the shell.
------
+------------------------------------------------------------------------
### 9.3.1 Hook Functions
-
-
+
For the functions below, it is possible to define an array that has the
-same name as the function with ‘`_functions`’ appended. Any element in
+same name as the function with ‘\_functions’ appended. Any element in
such an array is taken as the name of a function to execute; it is
-executed in the same context and with the same arguments as the basic
-function. For example, if `$chpwd_functions` is an array containing the
-values ‘`mychpwd`’, ‘`chpwd_save_dirstack`’, then the shell attempts to
-execute the functions ‘`chpwd`’, ‘`mychpwd`’ and
-‘`chpwd_save_dirstack`’, in that order. Any function that does not
-exist is silently ignored. A function found by this mechanism is
-referred to elsewhere as a ‘hook function’. An error in any function
-causes subsequent functions not to be run. Note further that an error in
-a `precmd` hook causes an immediately following `periodic` function not
-to run (though it may run at the next opportunity).
+executed in the same context and with the same arguments and same
+initial value of $? as the basic function. For example, if
+$chpwd_functions is an array containing the values ‘mychpwd’,
+‘chpwd_save_dirstack’, then the shell attempts to execute the functions
+‘chpwd’, ‘mychpwd’ and ‘chpwd_save_dirstack’, in that order. Any
+function that does not exist is silently ignored. A function found by
+this mechanism is referred to elsewhere as a *hook function*. An error
+in any function causes subsequent functions not to be run. Note further
+that an error in a precmd hook causes an immediately following periodic
+function not to run (though it may run at the next opportunity).
-
-
+
-`chpwd`
+chpwd
Executed whenever the current working directory is changed.
-
-
+
-`periodic`
+periodic
-If the parameter `PERIOD` is set, this function is executed every
-`$PERIOD` seconds, just before a prompt. Note that if multiple functions
-are defined using the array `periodic_functions` only one period is
-applied to the complete set of functions, and the scheduled time is not
-reset if the list of functions is altered. Hence the set of functions is
-always called together.
+If the parameter PERIOD is set, this function is executed every $PERIOD
+seconds, just before a prompt. Note that if multiple functions are
+defined using the array periodic_functions only one period is applied to
+the complete set of functions, and the scheduled time is not reset if
+the list of functions is altered. Hence the set of functions is always
+called together.
-
-
+
-`precmd`
+precmd
Executed before each prompt. Note that precommand functions are not
re-executed simply because the command line is redrawn, as happens, for
example, when a notification about an exiting job is displayed.
-
-
+
-`preexec`
+preexec
Executed just after a command has been read and is about to be executed.
If the history mechanism is active (regardless of whether the line was
@@ -343,10 +340,10 @@ size-limited version of the command (with things like function bodies
elided); the third argument contains the full text that is being
executed.
-
-
+
-`zshaddhistory`
+zshaddhistory
@@ -364,14 +361,14 @@ If any of the hook functions returns status 2 the history line will be
saved on the internal history list, but not written to the history file.
In case of a conflict, the first non-zero status value is taken.
-A hook function may call ‘`fc -p` `...`’ to switch the history context
-so that the history is saved in a different file from the that in the
-global `HISTFILE` parameter. This is handled specially: the history
-context is automatically restored after the processing of the history
-line is finished.
+A hook function may call ‘fc -p `...`’ to switch the history context so
+that the history is saved in a different file from that in the global
+HISTFILE parameter. This is handled specially: the history context is
+automatically restored after the processing of the history line is
+finished.
The following example function works with one of the options
-`INC_APPEND_HISTORY` or `SHARE_HISTORY` set, in order that the line is
+INC_APPEND_HISTORY or SHARE_HISTORY set, in order that the line is
written out immediately after the history entry is added. It first adds
the history line to the normal history with the newline stripped, which
is usually the correct behaviour. Then it switches the history context
@@ -380,7 +377,7 @@ directory.
-``` example
+```zsh
zshaddhistory() {
print -sr -- ${1%%$'\n'}
fc -p .zsh_local_history
@@ -389,17 +386,17 @@ zshaddhistory() {
-
-
+
-`zshexit`
+zshexit
Executed at the point where the main shell is about to exit normally.
-This is not called by exiting subshells, nor when the `exec` precommand
-modifier is used before an external command. Also, unlike `TRAPEXIT`, it
+This is not called by exiting subshells, nor when the exec precommand
+modifier is used before an external command. Also, unlike TRAPEXIT, it
is not called when functions exit.
------
+------------------------------------------------------------------------
@@ -408,80 +405,78 @@ is not called when functions exit.
The functions below are treated specially but do not have corresponding
hook arrays.
- - `TRAP``NAL`
-
-
-
- If defined and non-null, this function will be executed whenever the
- shell catches a signal `SIG``NAL`, where `NAL` is a signal name as
- specified for the `kill` builtin. The signal number will be passed
- as the first parameter to the function.
-
- If a function of this form is defined and null, the shell and
- processes spawned by it will ignore `SIG``NAL`.
-
- The return status from the function is handled specially. If it is
- zero, the signal is assumed to have been handled, and execution
- continues normally. Otherwise, the shell will behave as interrupted
- except that the return status of the trap is retained.
-
- Programs terminated by uncaught signals typically return the status
- 128 plus the signal number. Hence the following causes the handler
- for `SIGINT` to print a message, then mimic the usual effect of the
- signal.
-
-
-
- ``` example
- TRAPINT() {
- print "Caught SIGINT, aborting."
- return $(( 128 + $1 ))
- }
- ```
-
-
-
- The functions `TRAPZERR`, `TRAPDEBUG` and `TRAPEXIT` are never
- executed inside other traps.
-
-
+TRAP`NAL`
+
- - `TRAPDEBUG`
- If the option `DEBUG_BEFORE_CMD` is set (as it is by default),
- executed before each command; otherwise executed after each command.
- See the description of the `trap` builtin in [Shell Builtin
- Commands](Shell-Builtin-Commands.html#Shell-Builtin-Commands) for
- details of additional features provided in debug traps.
-
-
+If defined and non-null, this function will be executed whenever the
+shell catches a signal SIG`NAL`, where `NAL` is a signal name as
+specified for the kill builtin. The signal number will be passed as the
+first parameter to the function.
- - `TRAPEXIT`
- Executed when the shell exits, or when the current function exits if
- defined inside a function. The value of `$?` at the start of
- execution is the exit status of the shell or the return status of
- the function exiting.
-
-
+If a function of this form is defined and null, the shell and processes
+spawned by it will ignore SIG`NAL`.
- - `TRAPZERR`
- Executed whenever a command has a non-zero exit status. However, the
- function is not executed if the command occurred in a sublist
- followed by ‘`&&`’ or ‘`||`’; only the final command in a sublist of
- this type causes the trap to be executed. The function `TRAPERR`
- acts the same as `TRAPZERR` on systems where there is no `SIGERR`
- (this is the usual case).
+The return status from the function is handled specially. If it is zero,
+the signal is assumed to have been handled, and execution continues
+normally. Otherwise, the shell will behave as interrupted except that
+the return status of the trap is retained.
+
+Programs terminated by uncaught signals typically return the status 128
+plus the signal number. Hence the following causes the handler for
+SIGINT to print a message, then mimic the usual effect of the signal.
+
+
+
+```zsh
+TRAPINT() {
+ print "Caught SIGINT, aborting."
+ return $(( 128 + $1 ))
+}
+```
+
+
+
+The functions TRAPZERR, TRAPDEBUG and TRAPEXIT are never executed inside
+other traps.
+
+
+
+TRAPDEBUG
+If the option DEBUG_BEFORE_CMD is set (as it is by default), executed
+before each command; otherwise executed after each command. See the
+description of the trap builtin in [Shell Builtin
+Commands](Shell-Builtin-Commands.html#Shell-Builtin-Commands) for
+details of additional features provided in debug traps.
+
+
+
+TRAPEXIT
+Executed when the shell exits, or when the current function exits if
+defined inside a function. The value of $? at the start of execution is
+the exit status of the shell or the return status of the function
+exiting.
+
+
+
+TRAPZERR
+Executed whenever a command has a non-zero exit status. However, the
+function is not executed if the command occurred in a sublist followed
+by ‘&&’ or ‘\|\|’; only the final command in a sublist of this type
+causes the trap to be executed. The function TRAPERR acts the same as
+TRAPZERR on systems where there is no SIGERR (this is the usual case).
-The functions beginning ‘`TRAP`’ may alternatively be defined with the
-`trap` builtin: this may be preferable for some uses. Setting a trap
-with one form removes any trap of the other form for the same signal;
+The functions beginning ‘TRAP’ may alternatively be defined with the
+trap builtin: this may be preferable for some uses. Setting a trap with
+one form removes any trap of the other form for the same signal;
removing a trap in either form removes all traps for the same signal.
The forms
-``` example
+```zsh
TRAPNAL() {
# code
}
@@ -493,7 +488,7 @@ TRAPNAL() {
-``` example
+```zsh
trap '
# code
' NAL
@@ -504,19 +499,19 @@ trap '
(’list traps’) are equivalent in most ways, the exceptions being the
following:
- - Function traps have all the properties of normal functions,
+- Function traps have all the properties of normal functions,
appearing in the list of functions and being called with their own
function context rather than the context where the trap was
triggered.
- - The return status from function traps is special, whereas a return
+- The return status from function traps is special, whereas a return
from a list trap causes the surrounding context to return with the
given status.
- - Function traps are not reset within subshells, in accordance with
+- Function traps are not reset within subshells, in accordance with
zsh behaviour; list traps are reset, in accordance with POSIX
behaviour.
------
+------------------------------------------------------------------------
-This document was generated on *February 15, 2020* using
-[*texi2html 5.0*](http://www.nongnu.org/texi2html/).
-Zsh version 5.8, released on February 14, 2020.
+This document was generated on *May 14, 2022* using [*texi2html
+5.0*](http://www.nongnu.org/texi2html/).
+Zsh version 5.9, released on May 14, 2022.
diff --git a/zsh_manual/src/Introduction.md b/zsh_manual/src/Introduction.md
index b020147..7578588 100644
--- a/zsh_manual/src/Introduction.md
+++ b/zsh_manual/src/Introduction.md
@@ -30,7 +30,7 @@ Zsh has command line editing, builtin spelling correction, programmable
command completion, shell functions (with autoloading), a history
mechanism, and a host of other features.
------
+------------------------------------------------------------------------
@@ -38,14 +38,13 @@ mechanism, and a host of other features.
-Zsh was originally written by Paul Falstad `
`. Zsh is now
-maintained by the members of the zsh-workers mailing list
-``. The development is currently coordinated by
-Peter Stephenson ``. The coordinator can be contacted at
-``, but matters relating to the code should
-generally go to the mailing list.
+Zsh was originally written by Paul Falstad. Zsh is now maintained by the
+members of the zsh-workers mailing list \. The
+development is currently coordinated by Peter Stephenson \.
+The coordinator can be contacted at \, but matters
+relating to the code should generally go to the mailing list.
------
+------------------------------------------------------------------------
@@ -53,19 +52,19 @@ generally go to the mailing list.
Zsh is available from the following HTTP and anonymous FTP site.
-
-
-
+
-`ftp://ftp.zsh.org/pub/`
-`https://www.zsh.org/pub/` )
+
+
The up-to-date source code is available via Git from Sourceforge. See
-`https://sourceforge.net/projects/zsh/` for details. A summary of
+ for details. A summary of
instructions for the archive can be found at
-`http://zsh.sourceforge.net/`.
+.
------
+------------------------------------------------------------------------
@@ -73,32 +72,39 @@ instructions for the archive can be found at
-Zsh has 3 mailing lists:
+Zsh has several mailing lists:
- - ``
- Announcements about releases, major changes in the shell and the
- monthly posting of the Zsh FAQ. (moderated)
+\
+Announcements about releases, major changes in the shell and the monthly
+posting of the Zsh FAQ. (moderated)
- - ``
- User discussions.
+\
+User discussions.
- - ``
- Hacking, development, bug reports and patches.
+\
+Hacking, development, bug reports and patches.
+
+\
+Private mailing list (the general public cannot subscribe to it) for
+discussing bug reports with security implications, i.e., potential
+vulnerabilities.
+
+If you find a security problem in zsh itself, please mail this address.
To subscribe or unsubscribe, send mail to the associated administrative
address for the mailing list.
-``
+\
-``
+\
-``
+\
-``
+\
-``
+\
-``
+\
@@ -107,42 +113,39 @@ submissions to zsh-announce are automatically forwarded to zsh-users.
All submissions to zsh-users are automatically forwarded to zsh-workers.
If you have problems subscribing/unsubscribing to any of the mailing
-lists, send mail to ``. The mailing lists are
-maintained by Karsten Thygesen ``.
+lists, send mail to \.
The mailing lists are archived; the archives can be accessed via the
-administrative addresses listed above. There is also a hypertext
-archive, maintained by Geoff Wing ``, available at
-`https://www.zsh.org/mla/`.
+administrative addresses listed above. There is also a hypertext archive
+available at .
------
+------------------------------------------------------------------------
## 2.4 The Zsh FAQ
Zsh has a list of Frequently Asked Questions (FAQ), maintained by Peter
-Stephenson ``. It is regularly posted to the newsgroup
+Stephenson \. It is regularly posted to the newsgroup
comp.unix.shell and the zsh-announce mailing list. The latest version
can be found at any of the Zsh FTP sites, or at
-`http://www.zsh.org/FAQ/`. The contact address for FAQ-related matters
-is ``.
+. The contact address for FAQ-related matters
+is \.
------
+------------------------------------------------------------------------
-
-
+
## 2.5 The Zsh Web Page
-Zsh has a web page which is located at `https://www.zsh.org/`. This is
-maintained by Karsten Thygesen ``, of SunSITE Denmark.
-The contact address for web-related matters is ``.
+Zsh has a web page which is located at . The
+contact address for web-related matters is \.
------
+------------------------------------------------------------------------
-
-
+
## 2.6 The Zsh Userguide
@@ -150,24 +153,23 @@ A userguide is currently in preparation. It is intended to complement
the manual, with explanations and hints on issues where the manual can
be cabbalistic, hierographic, or downright mystifying (for example, the
word ‘hierographic’ does not exist). It can be viewed in its current
-state at `http://zsh.sourceforge.net/Guide/`. At the time of writing,
+state at . At the time of writing,
chapters dealing with startup files and their contents and the new
completion system were essentially complete.
------
+------------------------------------------------------------------------
## 2.7 See Also
-man page sh(1), man page csh(1), man page tcsh(1), man page rc(1), man
-page bash(1), man page ksh(1)
+sh(1), csh(1), tcsh(1), rc(1), bash(1), ksh(1)
IEEE Standard for information Technology - Part 2: Shell and Utilities,
IEEE Inc, 1993, ISBN 1-55937-255-9.
------
+------------------------------------------------------------------------
-This document was generated on *February 15, 2020* using
-[*texi2html 5.0*](http://www.nongnu.org/texi2html/).
-Zsh version 5.8, released on February 14, 2020.
+This document was generated on *May 14, 2022* using [*texi2html
+5.0*](http://www.nongnu.org/texi2html/).
+Zsh version 5.9, released on May 14, 2022.
diff --git a/zsh_manual/src/Invocation.md b/zsh_manual/src/Invocation.md
index 37d456d..5278a00 100644
--- a/zsh_manual/src/Invocation.md
+++ b/zsh_manual/src/Invocation.md
@@ -9,213 +9,212 @@
-
+
# 4 Invocation
------
+------------------------------------------------------------------------
-
+
## 4.1 Invocation
-
-
-
-
+
The following flags are interpreted by the shell when invoked to
determine where the shell will read commands from:
- - `-c`
- Take the first argument as a command to execute, rather than reading
- commands from a script or standard input. If any further arguments
- are given, the first one is assigned to `$0`, rather than being used
- as a positional parameter.
+-c
+Take the first argument as a command to execute, rather than reading
+commands from a script or standard input. If any further arguments are
+given, the first one is assigned to $0, rather than being used as a
+positional parameter.
- - `-i`
- Force shell to be interactive. It is still possible to specify a
- script to execute.
+-i
+Force shell to be interactive. It is still possible to specify a script
+to execute.
- - `-s`
- Force shell to read commands from the standard input. If the `-s`
- flag is not present and an argument is given, the first argument is
- taken to be the pathname of a script to execute.
+-s
+Force shell to read commands from the standard input. If the -s flag is
+not present and an argument is given, the first argument is taken to be
+the pathname of a script to execute.
If there are any remaining arguments after option processing, and
-neither of the options `-c` or `-s` was supplied, the first argument is
+neither of the options -c or -s was supplied, the first argument is
taken as the file name of a script containing shell commands to be
-executed. If the option `PATH_SCRIPT` is set, and the file name does not
-contain a directory path (i.e. there is no ‘`/`’ in the name), first the
-current directory and then the command path given by the variable `PATH`
+executed. If the option PATH_SCRIPT is set, and the file name does not
+contain a directory path (i.e. there is no ‘/’ in the name), first the
+current directory and then the command path given by the variable PATH
are searched for the script. If the option is not set or the file name
-contains a ‘`/`’ it is used directly.
+contains a ‘/’ it is used directly.
After the first one or two arguments have been appropriated as described
above, the remaining arguments are assigned to the positional
parameters.
-For further options, which are common to invocation and the `set`
-builtin, see [Options](Options.html#Options).
+For further options, which are common to invocation and the set builtin,
+see [Options](Options.html#Options).
-The long option ‘`-``-emulate`’ followed (in a separate word) by an
+The long option ‘--emulate’ followed (in a separate word) by an
emulation mode may be passed to the shell. The emulation modes are those
-described for the `emulate` builtin, see [Shell Builtin
+described for the emulate builtin, see [Shell Builtin
Commands](Shell-Builtin-Commands.html#Shell-Builtin-Commands). The
-‘`-``-emulate`’ option must precede any other options (which might
-otherwise be overridden), but following options are honoured, so may be
-used to modify the requested emulation mode. Note that certain extra
-steps are taken to ensure a smooth emulation when this option is used
-compared with the `emulate` command within the shell: for example,
-variables that conflict with POSIX usage such as `path` are not defined
-within the shell.
+‘--emulate’ option must precede any other options (which might otherwise
+be overridden), but following options are honoured, so may be used to
+modify the requested emulation mode. Note that certain extra steps are
+taken to ensure a smooth emulation when this option is used compared
+with the emulate command within the shell: for example, variables that
+conflict with POSIX usage such as path are not defined within the shell.
-Options may be specified by name using the `-o` option. `-o` acts like a
+Options may be specified by name using the -o option. -o acts like a
single-letter option, but takes a following string as the option name.
For example,
-``` example
+```zsh
zsh -x -o shwordsplit scr
```
-runs the script `scr`, setting the `XTRACE` option by the corresponding
-letter ‘`-x`’ and the `SH_WORD_SPLIT` option by name. Options may be
-turned *off* by name by using `+o` instead of `-o`. `-o` can be stacked
-up with preceding single-letter options, so for example ‘`-xo
-shwordsplit`’ or ‘`-xoshwordsplit`’ is equivalent to ‘`-x -o
-shwordsplit`’.
+runs the script scr, setting the XTRACE option by the corresponding
+letter ‘-x’ and the SH_WORD_SPLIT option by name. Options may be turned
+*off* by name by using +o instead of -o. -o can be stacked up with
+preceding single-letter options, so for example ‘-xo shwordsplit’ or
+‘-xoshwordsplit’ is equivalent to ‘-x -o shwordsplit’.
Options may also be specified by name in GNU long option style,
-‘`-``-``option-name`’. When this is done, ‘`-`’ characters in the
-option name are permitted: they are translated into ‘`_`’, and thus
-ignored. So, for example, ‘`zsh -``-sh-word-split`’ invokes zsh with the
-`SH_WORD_SPLIT` option turned on. Like other option syntaxes, options
-can be turned off by replacing the initial ‘`-`’ with a ‘`+`’; thus
-‘`+-sh-word-split`’ is equivalent to ‘`-``-no-sh-word-split`’. Unlike
-other option syntaxes, GNU-style long options cannot be stacked with any
-other options, so for example ‘`-x-shwordsplit`’ is an error, rather
-than being treated like ‘`-x -``-shwordsplit`’.
+‘--`option-name`’. When this is done, ‘-’ characters in the option name
+are permitted: they are translated into ‘\_’, and thus ignored. So, for
+example, ‘zsh --sh-word-split’ invokes zsh with the SH_WORD_SPLIT option
+turned on. Like other option syntaxes, options can be turned off by
+replacing the initial ‘-’ with a ‘+’; thus ‘+-sh-word-split’ is
+equivalent to ‘--no-sh-word-split’. Unlike other option syntaxes,
+GNU-style long options cannot be stacked with any other options, so for
+example ‘-x-shwordsplit’ is an error, rather than being treated like ‘-x
+--shwordsplit’.
-
-
+
-The special GNU-style option ‘`-``-version`’ is handled; it sends to
+The special GNU-style option ‘--version’ is handled; it sends to
standard output the shell’s version information, then exits
-successfully. ‘`-``-help`’ is also handled; it sends to standard output
-a list of options that can be used when invoking the shell, then exits
+successfully. ‘--help’ is also handled; it sends to standard output a
+list of options that can be used when invoking the shell, then exits
successfully.
Option processing may be finished, allowing following arguments that
-start with ‘`-`’ or ‘`+`’ to be treated as normal arguments, in two
-ways. Firstly, a lone ‘`-`’ (or ‘`+`’) as an argument by itself ends
-option processing. Secondly, a special option ‘`-``-`’ (or ‘`+-`’),
-which may be specified on its own (which is the standard POSIX usage) or
-may be stacked with preceding options (so ‘`-x-`’ is equivalent to ‘`-x
--``-`’). Options are not permitted to be stacked after ‘`-``-`’ (so
-‘`-x-f`’ is an error), but note the GNU-style option form discussed
-above, where ‘`-``-shwordsplit`’ is permitted and does not end option
-processing.
+start with ‘-’ or ‘+’ to be treated as normal arguments, in two ways.
+Firstly, a lone ‘-’ (or ‘+’) as an argument by itself ends option
+processing. Secondly, a special option ‘--’ (or ‘+-’), which may be
+specified on its own (which is the standard POSIX usage) or may be
+stacked with preceding options (so ‘-x-’ is equivalent to ‘-x --’).
+Options are not permitted to be stacked after ‘--’ (so ‘-x-f’ is an
+error), but note the GNU-style option form discussed above, where
+‘--shwordsplit’ is permitted and does not end option processing.
Except when the sh/ksh emulation single-letter options are in effect,
-the option ‘`-b`’ (or ‘`+b`’) ends option processing. ‘`-b`’ is like
-‘`-``-`’, except that further single-letter options can be stacked
-after the ‘`-b`’ and will take effect as normal.
+the option ‘-b’ (or ‘+b’) ends option processing. ‘-b’ is like ‘--’,
+except that further single-letter options can be stacked after the ‘-b’
+and will take effect as normal.
------
+------------------------------------------------------------------------
## 4.2 Compatibility
-
-
-
+
-Zsh tries to emulate sh or ksh when it is invoked as `sh` or `ksh`
+Zsh tries to emulate sh or ksh when it is invoked as sh or ksh
respectively; more precisely, it looks at the first letter of the name
-by which it was invoked, excluding any initial ‘`r`’ (assumed to stand
-for ‘restricted’), and if that is ‘`b`’, ‘`s`’ or ‘`k`’ it will emulate
-sh or ksh. Furthermore, if invoked as `su` (which happens on certain
-systems when the shell is executed by the `su` command), the shell will
-try to find an alternative name from the `SHELL` environment variable
-and perform emulation based on that.
+by which it was invoked, excluding any initial ‘r’ (assumed to stand for
+‘restricted’), and if that is ‘b’, ‘s’ or ‘k’ it will emulate sh or ksh.
+Furthermore, if invoked as su (which happens on certain systems when the
+shell is executed by the su command), the shell will try to find an
+alternative name from the SHELL environment variable and perform
+emulation based on that.
In sh and ksh compatibility modes the following parameters are not
-special and not initialized by the shell: `ARGC`, `argv`, `cdpath`,
-`fignore`, `fpath`, `HISTCHARS`, `mailpath`, `MANPATH`, `manpath`,
-`path`, `prompt`, `PROMPT`, `PROMPT2`, `PROMPT3`, `PROMPT4`, `psvar`,
-`status`, `watch`.
+special and not initialized by the shell: ARGC, argv, cdpath, fignore,
+fpath, HISTCHARS, mailpath, MANPATH, manpath, path, prompt, PROMPT,
+PROMPT2, PROMPT3, PROMPT4, psvar, status.
The usual zsh startup/shutdown scripts are not executed. Login shells
-source `/etc/profile` followed by `$HOME/.profile`. If the `ENV`
-environment variable is set on invocation, `$ENV` is sourced after the
-profile scripts. The value of `ENV` is subjected to parameter expansion,
-command substitution, and arithmetic expansion before being interpreted
-as a pathname. Note that the `PRIVILEGED` option also affects the
-execution of startup files.
+source /etc/profile followed by $HOME/.profile. If the ENV environment
+variable is set on invocation, $ENV is sourced after the profile
+scripts. The value of ENV is subjected to parameter expansion, command
+substitution, and arithmetic expansion before being interpreted as a
+pathname. Note that the PRIVILEGED option also affects the execution of
+startup files.
-The following options are set if the shell is invoked as `sh` or `ksh`:
-`NO_BAD_PATTERN`, `NO_BANG_HIST`, `NO_BG_NICE`, `NO_EQUALS`,
-`NO_FUNCTION_ARGZERO`, `GLOB_SUBST`, `NO_GLOBAL_EXPORT`, `NO_HUP`,
-`INTERACTIVE_COMMENTS`, `KSH_ARRAYS`, `NO_MULTIOS`, `NO_NOMATCH`,
-`NO_NOTIFY`, `POSIX_BUILTINS`, `NO_PROMPT_PERCENT`, `RM_STAR_SILENT`,
-`SH_FILE_EXPANSION`, `SH_GLOB`, `SH_OPTION_LETTERS`, `SH_WORD_SPLIT`.
-Additionally the `BSD_ECHO` and `IGNORE_BRACES` options are set if zsh
-is invoked as `sh`. Also, the `KSH_OPTION_PRINT`, `LOCAL_OPTIONS`,
-`PROMPT_BANG`, `PROMPT_SUBST` and `SINGLE_LINE_ZLE` options are set if
-zsh is invoked as `ksh`.
+The following options are set if the shell is invoked as sh or ksh:
+NO_BAD_PATTERN, NO_BANG_HIST, NO_BG_NICE, NO_EQUALS,
+NO_FUNCTION_ARGZERO, GLOB_SUBST, NO_GLOBAL_EXPORT, NO_HUP,
+INTERACTIVE_COMMENTS, KSH_ARRAYS, NO_MULTIOS, NO_NOMATCH, NO_NOTIFY,
+POSIX_BUILTINS, NO_PROMPT_PERCENT, RM_STAR_SILENT, SH_FILE_EXPANSION,
+SH_GLOB, SH_OPTION_LETTERS, SH_WORD_SPLIT. Additionally the BSD_ECHO and
+IGNORE_BRACES options are set if zsh is invoked as sh. Also, the
+KSH_OPTION_PRINT, LOCAL_OPTIONS, PROMPT_BANG, PROMPT_SUBST and
+SINGLE_LINE_ZLE options are set if zsh is invoked as ksh.
------
+Please note that, whilst reasonable efforts are taken to address
+incompatibilities when they arise, zsh does not guarantee complete
+emulation of other shells, nor POSIX compliance. For more information on
+the differences between zsh and other shells, please refer to chapter 2
+of the shell FAQ, .
-
-
+------------------------------------------------------------------------
+
+
## 4.3 Restricted Shell
-
-
+
When the basename of the command used to invoke zsh starts with the
-letter ‘`r`’ or the ‘`-r`’ command line option is supplied at
-invocation, the shell becomes restricted. Emulation mode is determined
-after stripping the letter ‘`r`’ from the invocation name. The following
-are disabled in restricted mode:
+letter ‘r’ or the ‘-r’ command line option is supplied at invocation,
+the shell becomes restricted. Emulation mode is determined after
+stripping the letter ‘r’ from the invocation name. The following are
+disabled in restricted mode:
- - changing directories with the `cd` builtin
- - changing or unsetting the `EGID`, `EUID`, `GID`, `HISTFILE`,
- `HISTSIZE`, `IFS`, `LD_AOUT_LIBRARY_PATH`, `LD_AOUT_PRELOAD`,
- `LD_LIBRARY_PATH`, `LD_PRELOAD`, `MODULE_PATH`, `module_path`,
- `PATH`, `path`, `SHELL`, `UID` and `USERNAME` parameters
- - specifying command names containing `/`
- - specifying command pathnames using `hash`
- - redirecting output to files
- - using the `exec` builtin command to replace the shell with another
+- changing directories with the cd builtin
+- changing or unsetting the EGID, EUID, GID, HISTFILE, HISTSIZE, IFS,
+ LD_AOUT_LIBRARY_PATH, LD_AOUT_PRELOAD, LD_LIBRARY_PATH, LD_PRELOAD,
+ MODULE_PATH, module_path, PATH, path, SHELL, UID and USERNAME
+ parameters
+- specifying command names containing /
+- specifying command pathnames using hash
+- redirecting output to files
+- using the exec builtin command to replace the shell with another
command
- - using `jobs -Z` to overwrite the shell process’ argument and
+- using jobs -Z to overwrite the shell process’ argument and
environment space
- - using the `ARGV0` parameter to override `argv[0]` for external
+- using the ARGV0 parameter to override argv\[0\] for external
commands
- - turning off restricted mode with `set +r` or `unsetopt RESTRICTED`
+- turning off restricted mode with set +r or unsetopt RESTRICTED
These restrictions are enforced after processing the startup files. The
-startup files should set up `PATH` to point to a directory of commands
+startup files should set up PATH to point to a directory of commands
which can be safely invoked in the restricted environment. They may also
add further restrictions by disabling selected builtins.
-Restricted mode can also be activated any time by setting the
-`RESTRICTED` option. This immediately enables all the restrictions
-described above even if the shell still has not processed all startup
-files.
+Restricted mode can also be activated any time by setting the RESTRICTED
+option. This immediately enables all the restrictions described above
+even if the shell still has not processed all startup files.
A shell *Restricted Mode* is an outdated way to restrict what users may
do: modern systems have better, safer and more reliable ways to confine
@@ -227,11 +226,11 @@ may be removed in a future version of zsh.
It is important to realise that the restrictions only apply to the
shell, not to the commands it runs (except for some shell builtins).
While a restricted shell can only run the restricted list of commands
-accessible via the predefined ‘`PATH`’ variable, it does not prevent
-those commands from running any other command.
+accessible via the predefined ‘PATH’ variable, it does not prevent those
+commands from running any other command.
-As an example, if ‘`env`’ is among the list of *allowed* commands, then
-it allows the user to run any command as ‘`env`’ is not a shell
+As an example, if ‘env’ is among the list of *allowed* commands, then it
+allows the user to run any command as ‘env’ is not a shell
So when implementing a restricted shell framework it is important to be
fully aware of what actions each of the *allowed* commands or features
@@ -241,26 +240,26 @@ Many commands can have their behaviour affected by environment
variables. Except for the few listed above, zsh does not restrict the
setting of environment variables.
-If a ‘`perl`’, ‘`python`’, ‘`bash`’, or other general purpose
-interpreted script it treated as a restricted command, the user can work
-around the restriction by setting specially crafted ‘`PERL5LIB`’,
-‘`PYTHONPATH`’, ‘`BASHENV`’ (etc.) environment variables. On GNU
-systems, any command can be made to run arbitrary code when performing
-character set conversion (including zsh itself) by setting a
-‘`GCONV_PATH`’ environment variable. Those are only a few examples.
+If a ‘perl’, ‘python’, ‘bash’, or other general purpose interpreted
+script it treated as a restricted command, the user can work around the
+restriction by setting specially crafted ‘PERL5LIB’, ‘PYTHONPATH’,
+‘BASHENV’ (etc.) environment variables. On GNU systems, any command can
+be made to run arbitrary code when performing character set conversion
+(including zsh itself) by setting a ‘GCONV_PATH’ environment variable.
+Those are only a few examples.
-Bear in mind that, contrary to some other shells, ‘`readonly`’ is not a
+Bear in mind that, contrary to some other shells, ‘readonly’ is not a
security feature in zsh as it can be undone and so cannot be used to
mitigate the above.
A restricted shell only works if the allowed commands are few and
carefully written so as not to grant more access to users than intended.
It is also important to restrict what zsh module the user may load as
-some of them, such as ‘`zsh/system`’, ‘`zsh/mapfile`’ and ‘`zsh/files`’,
-allow bypassing most of the restrictions.
+some of them, such as ‘zsh/system’, ‘zsh/mapfile’ and ‘zsh/files’, allow
+bypassing most of the restrictions.
------
+------------------------------------------------------------------------
-This document was generated on *February 15, 2020* using
-[*texi2html 5.0*](http://www.nongnu.org/texi2html/).
-Zsh version 5.8, released on February 14, 2020.
+This document was generated on *May 14, 2022* using [*texi2html
+5.0*](http://www.nongnu.org/texi2html/).
+Zsh version 5.9, released on May 14, 2022.
diff --git a/zsh_manual/src/Jobs-&-Signals.md b/zsh_manual/src/Jobs-&-Signals.md
index 7c5cbd4..e042567 100644
--- a/zsh_manual/src/Jobs-&-Signals.md
+++ b/zsh_manual/src/Jobs-&-Signals.md
@@ -8,28 +8,28 @@
-
-
+
# 10 Jobs & Signals
------
+------------------------------------------------------------------------
## 10.1 Jobs
-
-
+
-If the `MONITOR` option is set, an interactive shell associates a *job*
+If the MONITOR option is set, an interactive shell associates a *job*
with each pipeline. command, and assigns them small integer numbers.
-When a job is started asynchronously with ‘`&`’, the shell prints a line
+When a job is started asynchronously with ‘&’, the shell prints a line
to standard error which looks like:
-``` example
+```zsh
[1] 1234
```
@@ -38,22 +38,22 @@ to standard error which looks like:
indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process ID was 1234.
-If a job is started with ‘`&|`’ or ‘`&!`’, then that job is immediately
+If a job is started with ‘&\|’ or ‘&!’, then that job is immediately
disowned. After startup, it to the job control features described here.
If you are running a job and wish to do something else you may hit the
-key ^Z (control-Z) which sends a `TSTP` signal to the current job: this
-key may be redefined by the `susp` option of the external `stty`
-command.
-
The shell will then normally
-indicate that the job has been ‘suspended’, and print another prompt.
-You can then manipulate the state of this job,
-
putting it in the background
-with the `bg` command, or run some other commands and then eventually
-bring the job back into the foreground with
-
the foreground command `fg`. A
-^Z takes effect immediately and is like an interrupt in that pending
-output and unread input are discarded when it is typed.
+key ^Z (control-Z) which sends a TSTP signal to the current job: this
+key may be redefined by the susp option of the external stty command.
+
The shell will then normally indicate
+that the job has been ‘suspended’, and print another prompt. You can
+then manipulate the state of this job,
putting it in the background with the
+bg command, or run some other commands and then eventually bring the job
+back into the foreground with
+the foreground command fg. A ^Z takes effect immediately and is like an
+interrupt in that pending output and unread input are discarded when it
+is typed.
A job being run in the background will suspend if it tries to read from
the terminal.
@@ -62,109 +62,109 @@ Note that if the job running in the foreground is a shell function, then
suspending it will have the effect of causing the shell to fork. This is
necessary to separate the function’s state from that of the parent shell
performing the job control, so that the latter can return to the command
-line prompt. As a result, even if `fg` is used to continue the job the
+line prompt. As a result, even if fg is used to continue the job the
function will no longer be part of the parent shell, and any variables
set by the function will not be visible in the parent shell. Thus the
behaviour is different from the case where the function was never
suspended. Zsh is different from many other shells in this regard.
-One additional side effect is that use of `disown` with a job created by
+One additional side effect is that use of disown with a job created by
suspending shell code in this fashion is delayed: the job can only be
disowned once any process started from the parent shell has terminated.
At that point, the disowned job disappears silently from the job list.
The same behaviour is found when the shell is executing code as the
-right hand side of a pipeline or any complex shell construct such as
-`if`, `for`, etc., in order that the entire block of code can be managed
-as a single job.
-
Background
-jobs are normally allowed to produce output, but this can be disabled by
-giving the command ‘`stty tostop`’. If you set this tty option, then
-background jobs will suspend when they try to produce output like they
-do when they try to read input.
+right hand side of a pipeline or any complex shell construct such as if,
+for, etc., in order that the entire block of code can be managed as a
+single job.
Background jobs are
+normally allowed to produce output, but this can be disabled by giving
+the command ‘stty tostop’. If you set this tty option, then background
+jobs will suspend when they try to produce output like they do when they
+try to read input.
-When a command is suspended and continued later with the `fg` or `wait`
+When a command is suspended and continued later with the fg or wait
builtins, zsh restores tty modes that were in effect when it was
suspended. This (intentionally) does not apply if the command is
-continued via ‘`kill -CONT`’, nor when it is continued with `bg`.
+continued via ‘kill -CONT’, nor when it is continued with bg.
-
-
+
There are several ways to refer to jobs in the shell. A job can be
referred to by the process ID of any process of the job or by one of the
following:
- - `%``number`
- The job with the given number.
+%`number`
+The job with the given number.
- - `%``string`
- The last job whose command line begins with `string`.
+%`string`
+The last job whose command line begins with `string`.
- - `%?``string`
- The last job whose command line contains `string`.
+%?`string`
+The last job whose command line contains `string`.
- - `%%`
- Current job.
+%%
+Current job.
- - `%+`
- Equivalent to ‘`%%`’.
+%+
+Equivalent to ‘%%’.
- - `%-`
- Previous job.
+%-
+Previous job.
-The shell learns immediately whenever a process changes state.
-
It normally informs you
-whenever a job becomes blocked so that no further progress is possible.
-If the `NOTIFY` option is not set, it waits until just before it prints
-a prompt before it informs you. All such notifications are sent directly
-to the terminal, not to the standard output or standard error.
+The shell learns immediately whenever a process changes state.
It normally informs you whenever a
+job becomes blocked so that no further progress is possible. If the
+NOTIFY option is not set, it waits until just before it prints a prompt
+before it informs you. All such notifications are sent directly to the
+terminal, not to the standard output or standard error.
When the monitor mode is on, each background job that completes triggers
-any trap set for `CHLD`.
+any trap set for CHLD.
When you try to leave the shell while jobs are running or suspended, you
will be warned that ‘You have suspended (running) jobs’. You may use the
-`jobs` command to see what they are. If you do this or immediately try
-to exit again, the shell will not warn you a second time; the suspended
-jobs will be terminated, and the running jobs will be sent a `SIGHUP`
-signal, if the `HUP` option is set.
-
+jobs command to see what they are. If you do this or immediately try to
+exit again, the shell will not warn you a second time; the suspended
+jobs will be terminated, and the running jobs will be sent a SIGHUP
+signal, if the HUP option is set.
-
-
-
+
To avoid having the shell terminate the running jobs, either use the
-nohup command (see man page nohup(1)) or the `disown` builtin.
+nohup(1) command or the disown builtin.
------
+------------------------------------------------------------------------
## 10.2 Signals
-The `INT` and `QUIT` signals for an invoked command are ignored if the
-command is followed by ‘`&`’ and the `MONITOR` option is not active. The
-shell itself always ignores the `QUIT` signal. Otherwise, signals have
-the values inherited by the shell from its parent (but see the
-`TRAP``NAL` special functions in [Functions](Functions.html#Functions)).
+The INT and QUIT signals for an invoked command are ignored if the
+command is followed by ‘&’ and the MONITOR option is not active. The
+shell itself always ignores the QUIT signal. Otherwise, signals have the
+values inherited by the shell from its parent (but see the TRAP`NAL`
+special functions in [Functions](Functions.html#Functions)).
-
-
-
+
Certain jobs are run asynchronously by the shell other than those
explicitly put into the background; even in cases where the shell would
-usually wait for such jobs, an explicit `exit` command or exit due to
-the option `ERR_EXIT` will cause the shell to exit without waiting.
-Examples of such asynchronous jobs are process substitution, see
-[Process Substitution](Expansion.html#Process-Substitution), and the
-handler processes for multios, see the section Multios in
+usually wait for such jobs, an explicit exit command or exit due to the
+option ERR_EXIT will cause the shell to exit without waiting. Examples
+of such asynchronous jobs are process substitution, see [Process
+Substitution](Expansion.html#Process-Substitution), and the handler
+processes for multios, see the section *Multios* in
[Redirection](Redirection.html#Redirection).
------
+------------------------------------------------------------------------
-This document was generated on *February 15, 2020* using
-[*texi2html 5.0*](http://www.nongnu.org/texi2html/).
-Zsh version 5.8, released on February 14, 2020.
+This document was generated on *May 14, 2022* using [*texi2html
+5.0*](http://www.nongnu.org/texi2html/).
+Zsh version 5.9, released on May 14, 2022.
diff --git a/zsh_manual/src/Options.md b/zsh_manual/src/Options.md
index d7ab6a5..d393129 100644
--- a/zsh_manual/src/Options.md
+++ b/zsh_manual/src/Options.md
@@ -25,658 +25,658 @@
-
+
# 16 Options
------
+------------------------------------------------------------------------
-
-
+
## 16.1 Specifying Options
Options are primarily referred to by name. These names are case
-insensitive and underscores are ignored. For example, ‘`allexport`’ is
-equivalent to ‘`A__lleXP_ort`’.
+insensitive and underscores are ignored. For example, ‘allexport’ is
+equivalent to ‘A\_\_lleXP_ort’.
-The sense of an option name may be inverted by preceding it with ‘`no`’,
-so ‘`setopt No_Beep`’ is equivalent to ‘`unsetopt beep`’. This inversion
-can only be done once, so ‘`nonobeep`’ is *not* a synonym for ‘`beep`’.
-Similarly, ‘`tify`’ is not a synonym for ‘`nonotify`’ (the inversion of
-‘`notify`’).
+The sense of an option name may be inverted by preceding it with ‘no’,
+so ‘setopt No_Beep’ is equivalent to ‘unsetopt beep’. This inversion can
+only be done once, so ‘nonobeep’ is *not* a synonym for ‘beep’.
+Similarly, ‘tify’ is not a synonym for ‘nonotify’ (the inversion of
+‘notify’).
Some options also have one or more single letter names. There are two
sets of single letter options: one used by default, and another used to
-emulate sh/ksh (used when the `SH_OPTION_LETTERS` option is set). The
+emulate sh/ksh (used when the SH_OPTION_LETTERS option is set). The
single letter options can be used on the shell command line, or with the
-`set`, `setopt` and `unsetopt` builtins, as normal Unix options preceded
-by ‘`-`’.
+set, setopt and unsetopt builtins, as normal Unix options preceded by
+‘-’.
-The sense of the single letter options may be inverted by using ‘`+`’
-instead of ‘`-`’. Some of the single letter option names refer to an
+The sense of the single letter options may be inverted by using ‘+’
+instead of ‘-’. Some of the single letter option names refer to an
option being off, in which case the inversion of that name refers to the
-option being on. For example, ‘`+n`’ is the short name of ‘`exec`’, and
-‘`-n`’ is the short name of its inversion, ‘`noexec`’.
+option being on. For example, ‘+n’ is the short name of ‘exec’, and ‘-n’
+is the short name of its inversion, ‘noexec’.
In strings of single letter options supplied to the shell at startup,
-trailing whitespace will be ignored; for example the string ‘` -f `’
-will be treated just as ‘`-f`’, but the string ‘`-f i`’ is an error.
-This is because many systems which implement the ‘`#!`’ mechanism for
-calling scripts do not strip trailing whitespace.
+trailing whitespace will be ignored; for example the string ‘-f ’ will
+be treated just as ‘-f’, but the string ‘-f i’ is an error. This is
+because many systems which implement the ‘#!’ mechanism for calling
+scripts do not strip trailing whitespace.
------
+It is possible for options to be set within a function scope. See the
+description of the option LOCAL_OPTIONS below.
-
-
+------------------------------------------------------------------------
+
+
## 16.2 Description of Options
In the following list, options set by default in all emulations are
-marked \
; those set by default only in csh, ksh, sh, or zsh
-emulations are marked \, \, \, \ as appropriate. When
-listing options (by ‘`setopt`’, ‘`unsetopt`’, ‘`set -o`’ or ‘`set +o`’),
-those turned on by default appear in the list prefixed with ‘`no`’.
-Hence (unless `KSH_OPTION_PRINT` is set), ‘`setopt`’ shows all options
-whose settings are changed from the default.
+marked \; those set by default only in csh, ksh, sh, or zsh
+emulations are marked \, \, \, \ as appropriate. When
+listing options (by ‘setopt’, ‘unsetopt’, ‘set -o’ or ‘set +o’), those
+turned on by default appear in the list prefixed with ‘no’. Hence
+(unless KSH_OPTION_PRINT is set), ‘setopt’ shows all options whose
+settings are changed from the default.
------
+------------------------------------------------------------------------
### 16.2.1 Changing Directories
-
-
-
-
+
+
-`AUTO_CD` (`-J`)
+AUTO_CD (-J)
If a command is issued that can’t be executed as a normal command, and
-the command is the name of a directory, perform the `cd` command to that
-directory. This option is only applicable if the option `SHIN_STDIN` is
+the command is the name of a directory, perform the cd command to that
+directory. This option is only applicable if the option SHIN_STDIN is
set, i.e. if commands are being read from standard input. The option is
-designed for interactive use; it is recommended that `cd` be used
+designed for interactive use; it is recommended that cd be used
explicitly in scripts to avoid ambiguity.
-
-
-
-
-
+
-`AUTO_PUSHD` (`-N`)
+AUTO_PUSHD (-N)
-Make `cd` push the old directory onto the directory stack.
+Make cd push the old directory onto the directory stack.
-
-
-
-
+
-`CDABLE_VARS` (`-T`)
+CDABLE_VARS (-T)
-If the argument to a `cd` command (or an implied `cd` with the `AUTO_CD`
+If the argument to a cd command (or an implied cd with the AUTO_CD
option set) is not a directory, and does not begin with a slash, try to
-expand the expression as if it were preceded by a ‘`~`’ (see [Filename
+expand the expression as if it were preceded by a ‘\~’ (see [Filename
Expansion](Expansion.html#Filename-Expansion)).
-
-
-
-
-
+
-`CD_SILENT`
+CD_SILENT
-Never print the working directory after a `cd` (whether explicit or
-implied with the `AUTO_CD` option set). `cd` normally prints the working
-directory when the argument given to it was `-`, a stack entry, or the
-name of a directory found under `CDPATH`. Note that this is distinct
-from `pushd`’s stack-printing behaviour, which is controlled by
-`PUSHD_SILENT`. This option overrides the printing-related effects of
-`POSIX_CD`.
+Never print the working directory after a cd (whether explicit or
+implied with the AUTO_CD option set). cd normally prints the working
+directory when the argument given to it was -, a stack entry, or the
+name of a directory found under CDPATH. Note that this is distinct from
+pushd’s stack-printing behaviour, which is controlled by PUSHD_SILENT.
+This option overrides the printing-related effects of POSIX_CD.
-
-
-
-
+
-`CHASE_DOTS`
+CHASE_DOTS
-When changing to a directory containing a path segment ‘`..`’ which
-would otherwise be treated as canceling the previous segment in the path
-(in other words, ‘`foo/..`’ would be removed from the path, or if ‘`..`’
-is the first part of the path, the last part of the current working
-directory would be removed), instead resolve the path to the physical
-directory. This option is overridden by `CHASE_LINKS`.
+When changing to a directory containing a path segment ‘..’ which would
+otherwise be treated as canceling the previous segment in the path (in
+other words, ‘foo/..’ would be removed from the path, or if ‘..’ is the
+first part of the path, the last part of the current working directory
+would be removed), instead resolve the path to the physical directory.
+This option is overridden by CHASE_LINKS.
-For example, suppose `/foo/bar` is a link to the directory `/alt/rod`.
-Without this option set, ‘`cd /foo/bar/..`’ changes to `/foo`; with it
-set, it changes to `/alt`. The same applies if the current directory is
-`/foo/bar` and ‘`cd ..`’ is used. Note that all other symbolic links in
-the path will also be resolved.
+For example, suppose /foo/bar is a link to the directory /alt/rod.
+Without this option set, ‘cd /foo/bar/..’ changes to /foo; with it set,
+it changes to /alt. The same applies if the current directory is
+/foo/bar and ‘cd ..’ is used. Note that all other symbolic links in the
+path will also be resolved.
-
-
-
-
-
-
+
+
-`CHASE_LINKS` (`-w`)
+CHASE_LINKS (-w)
Resolve symbolic links to their true values when changing directory.
-This also has the effect of `CHASE_DOTS`, i.e. a ‘`..`’ path segment
-will be treated as referring to the physical parent, even if the
-preceding path segment is a symbolic link.
+This also has the effect of CHASE_DOTS, i.e. a ‘..’ path segment will be
+treated as referring to the physical parent, even if the preceding path
+segment is a symbolic link.
-
-
-
+
-`POSIX_CD` \ \
+POSIX_CD \ \
-Modifies the behaviour of `cd`, `chdir` and `pushd` commands to make
-them more compatible with the POSIX standard. The behaviour with the
-option unset is described in the documentation for the `cd` builtin in
-[Shell Builtin
+Modifies the behaviour of cd, chdir and pushd commands to make them more
+compatible with the POSIX standard. The behaviour with the option unset
+is described in the documentation for the cd builtin in [Shell Builtin
Commands](Shell-Builtin-Commands.html#Shell-Builtin-Commands). If the
option is set, the shell does not test for directories beneath the local
-directory (‘`.`’) until after all directories in `cdpath` have been
-tested, and the `cd` and `chdir` commands do not recognise arguments of
-the form ‘{`+`|`-`}`n`’ as directory stack entries.
+directory (‘.’) until after all directories in cdpath have been tested,
+and the cd and chdir commands do not recognise arguments of the form
+‘{+\|-}`n`’ as directory stack entries.
Also, if the option is set, the conditions under which the shell prints
the new directory after changing to it are modified. It is no longer
restricted to interactive shells (although printing of the directory
-stack with `pushd` is still limited to interactive shells); and any use
-of a component of `CDPATH`, including a ‘`.`’ but excluding an empty
-component that is otherwise treated as ‘`.`’, causes the directory to be
-printed.
+stack with pushd is still limited to interactive shells); and any use of
+a component of CDPATH, including a ‘.’ but excluding an empty component
+that is otherwise treated as ‘.’, causes the directory to be printed.
-
-
-
-
-
+
-`PUSHD_IGNORE_DUPS`
+PUSHD_IGNORE_DUPS
Don’t push multiple copies of the same directory onto the directory
stack.
-
-
-
-
+
-`PUSHD_MINUS`
+PUSHD_MINUS
-Exchanges the meanings of ‘`+`’ and ‘`-`’ when used with a number to
-specify a directory in the stack.
+Exchanges the meanings of ‘+’ and ‘-’ when used with a number to specify
+a directory in the stack.
-
-
-
-
+
-`PUSHD_SILENT` (`-E`)
+PUSHD_SILENT (-E)
-Do not print the directory stack after `pushd` or `popd`.
+Do not print the directory stack after pushd or popd.
-
-
-
-
+
-`PUSHD_TO_HOME` (`-D`)
+PUSHD_TO_HOME (-D)
-Have `pushd` with no arguments act like ‘`pushd $HOME`’.
+Have pushd with no arguments act like ‘pushd $HOME’.
------
+------------------------------------------------------------------------
### 16.2.2 Completion
-
-
-
-
+
-`ALWAYS_LAST_PROMPT` \
+ALWAYS_LAST_PROMPT \
If unset, key functions that list completions try to return to the last
prompt if given a numeric argument. If set these functions try to return
to the last prompt if given *no* numeric argument.
-
-
-
-
+
-`ALWAYS_TO_END`
+ALWAYS_TO_END
If a completion is performed with the cursor within a word, and a full
completion is inserted, the cursor is moved to the end of the word. That
is, the cursor is moved to the end of the word if either a single match
is inserted or menu completion is performed.
-
-
-
-
+
-`AUTO_LIST` (`-9`) \
+AUTO_LIST (-9) \
Automatically list choices on an ambiguous completion.
-
-
-
-
+
-`AUTO_MENU` \
+AUTO_MENU \
Automatically use menu completion after the second consecutive request
for completion, for example by pressing the tab key repeatedly. This
-option is overridden by `MENU_COMPLETE`.
+option is overridden by MENU_COMPLETE.
-
-
-
-
+
-`AUTO_NAME_DIRS`
+AUTO_NAME_DIRS
Any parameter that is set to the absolute name of a directory
immediately becomes a name for that directory, that will be used by the
-‘`%~`’ and related prompt sequences, and will be available when
-completion is performed on a word starting with ‘`~`’. (Otherwise, the
-parameter must be used in the form ‘`~``param`’ first.)
+‘%\~’ and related prompt sequences, and will be available when
+completion is performed on a word starting with ‘\~’. (Otherwise, the
+parameter must be used in the form ‘\~`param`’ first.)
-
-
-
-
+
-`AUTO_PARAM_KEYS` \
+AUTO_PARAM_KEYS \
If a parameter name was completed and a following character (normally a
space) automatically inserted, and the next character typed is one of
-those that have to come directly after the name (like ‘`}`’, ‘`:`’,
-etc.), the automatically added character is deleted, so that the
-character typed comes immediately after the parameter name. Completion
-in a brace expansion is affected similarly: the added character is a
-‘`,`’, which will be removed if ‘`}`’ is typed next.
+those that have to come directly after the name (like ‘}’, ‘:’, etc.),
+the automatically added character is deleted, so that the character
+typed comes immediately after the parameter name. Completion in a brace
+expansion is affected similarly: the added character is a ‘,’, which
+will be removed if ‘}’ is typed next.
-
-
-
-
+
-`AUTO_PARAM_SLASH` \
+AUTO_PARAM_SLASH \
If a parameter is completed whose content is the name of a directory,
then add a trailing slash instead of a space.
-
-
-
-
-
+
-`AUTO_REMOVE_SLASH` \
+AUTO_REMOVE_SLASH \
When the last character resulting from a completion is a slash and the
next character typed is a word delimiter, a slash, or a character that
ends a command (such as a semicolon or an ampersand), remove the slash.
-
-
-
-
+
-`BASH_AUTO_LIST`
+BASH_AUTO_LIST
On an ambiguous completion, automatically list choices when the
completion function is called twice in succession. This takes precedence
-over `AUTO_LIST`. The setting of `LIST_AMBIGUOUS` is respected. If
-`AUTO_MENU` is set, the menu behaviour will then start with the third
-press. Note that this will not work with `MENU_COMPLETE`, since repeated
-completion calls immediately cycle through the list in that case.
+over AUTO_LIST. The setting of LIST_AMBIGUOUS is respected. If AUTO_MENU
+is set, the menu behaviour will then start with the third press. Note
+that this will not work with MENU_COMPLETE, since repeated completion
+calls immediately cycle through the list in that case.
-
-
-
-
-
+
-`COMPLETE_ALIASES`
+COMPLETE_ALIASES
Prevents aliases on the command line from being internally substituted
before completion is attempted. The effect is to make the alias a
distinct command for completion purposes.
-
-
-
-
+
-`COMPLETE_IN_WORD`
+COMPLETE_IN_WORD
If unset, the cursor is set to the end of the word if completion is
started. Otherwise it stays there and completion is done from both ends.
-
-
-
-
+
-`GLOB_COMPLETE`
+GLOB_COMPLETE
When the current word has a glob pattern, do not insert all the words
resulting from the expansion but generate matches as for completion and
-cycle through them like `MENU_COMPLETE`. The matches are generated as if
-a ‘`*`’ was added to the end of the word, or inserted at the cursor when
-`COMPLETE_IN_WORD` is set. This actually uses pattern matching, not
+cycle through them like MENU_COMPLETE. The matches are generated as if a
+‘\*’ was added to the end of the word, or inserted at the cursor when
+COMPLETE_IN_WORD is set. This actually uses pattern matching, not
globbing, so it works not only for files but for any completion, such as
options, user names, etc.
Note that when the pattern matcher is used, matching control (for
example, case-insensitive or anchored matching) cannot be used. This
limitation only applies when the current word contains a pattern; simply
-turning on the `GLOB_COMPLETE` option does not have this effect.
+turning on the GLOB_COMPLETE option does not have this effect.
-
-
-
-
+
-`HASH_LIST_ALL` \
+HASH_LIST_ALL \
Whenever a command completion or spelling correction is attempted, make
sure the entire command path is hashed first. This makes the first
completion slower but avoids false reports of spelling errors.
-
-
-
-
-
-
+
-`LIST_AMBIGUOUS` \
+LIST_AMBIGUOUS \
-This option works when `AUTO_LIST` or `BASH_AUTO_LIST` is also set. If
-there is an unambiguous prefix to insert on the command line, that is
-done without a completion list being displayed; in other words,
-auto-listing behaviour only takes place when nothing would be inserted.
-In the case of `BASH_AUTO_LIST`, this means that the list will be
-delayed to the third call of the function.
+This option works when AUTO_LIST or BASH_AUTO_LIST is also set. If there
+is an unambiguous prefix to insert on the command line, that is done
+without a completion list being displayed; in other words, auto-listing
+behaviour only takes place when nothing would be inserted. In the case
+of BASH_AUTO_LIST, this means that the list will be delayed to the third
+call of the function.
-
-
-
-
-
+
-`LIST_BEEP` \
+LIST_BEEP \
Beep on an ambiguous completion. More accurately, this forces the
completion widgets to return status 1 on an ambiguous completion, which
-causes the shell to beep if the option `BEEP` is also set; this may be
+causes the shell to beep if the option BEEP is also set; this may be
modified if completion is called from a user-defined widget.
-
-
-
-
+
-`LIST_PACKED`
+LIST_PACKED
Try to make the completion list smaller (occupying less lines) by
printing the matches in columns with different widths.
-
-
-
-
-
+
-`LIST_ROWS_FIRST`
+LIST_ROWS_FIRST
Lay out the matches in completion lists sorted horizontally, that is,
the second match is to the right of the first one, not under it as
usual.
-
-
-
-
-
+
-`LIST_TYPES` (`-X`) \
+LIST_TYPES (-X) \
When listing files that are possible completions, show the type of each
file with a trailing identifying mark.
-
-
-
-
+
-`MENU_COMPLETE` (`-Y`)
+MENU_COMPLETE (-Y)
On an ambiguous completion, instead of listing possibilities or beeping,
insert the first match immediately. Then when completion is requested
again, remove the first match and insert the second match, etc. When
there are no more matches, go back to the first one again.
-`reverse-menu-complete` may be used to loop through the list in the
-other direction. This option overrides `AUTO_MENU`.
+reverse-menu-complete may be used to loop through the list in the other
+direction. This option overrides AUTO_MENU.
-
-
-
-
+
-`REC_EXACT` (`-S`)
+REC_EXACT (-S)
If the string on the command line exactly matches one of the possible
completions, it is accepted, even if there is another completion (i.e.
that string with something else added) that also matches.
------
+------------------------------------------------------------------------
### 16.2.3 Expansion and Globbing
-
-
-
-
-
-
+
+
-`BAD_PATTERN` (`+2`) \ \
+BAD_PATTERN (+2) \ \
If a pattern for filename generation is badly formed, print an error
message. (If this option is unset, the pattern will be left unchanged.)
-
-
-
-
-
-
+
+
-`BARE_GLOB_QUAL` \
+BARE_GLOB_QUAL \
In a glob pattern, treat a trailing set of parentheses as a qualifier
-list, if it contains no ‘`|`’, ‘`(`’ or (if special) ‘`~`’ characters.
-See [Filename Generation](Expansion.html#Filename-Generation).
+list, if it contains no ‘\|’, ‘(’ or (if special) ‘\~’ characters. See
+[Filename Generation](Expansion.html#Filename-Generation).
-
-
-
-
-
+
-`BRACE_CCL`
+BRACE_CCL
Expand expressions in braces which would not otherwise undergo brace
expansion to a lexically ordered list of all the characters. See [Brace
Expansion](Expansion.html#Brace-Expansion).
-
-
-
-
+
-`CASE_GLOB` \
+CASE_GLOB \
Make globbing (filename generation) sensitive to case. Note that other
uses of patterns are always sensitive to case. If the option is unset,
the presence of any character which is special to filename generation
-will cause case-insensitive matching. For example, `cvs(/)` can match
-the directory `CVS` owing to the presence of the globbing flag (unless
-the option `BARE_GLOB_QUAL` is unset).
+will cause case-insensitive matching. For example, cvs(/) can match the
+directory CVS owing to the presence of the globbing flag (unless the
+option BARE_GLOB_QUAL is unset).
-
-
-
-
-
+
+
-`CASE_MATCH` \
+CASE_MATCH \
-Make regular expressions using the `zsh/regex` module (including matches
-with `=~`) sensitive to case.
+Make regular expressions using the zsh/regex module (including matches
+with =\~) sensitive to case.
-
-
-
-
-
-
-
+
-`CSH_NULL_GLOB` \
+CASE_PATHS
+
+If CASE_PATHS is not set (the default), CASE_GLOB affects the
+interpretation of *every* path component, whenever a special character
+appears in *any* component. When CASE_PATHS is set, file path components
+that do *not* contain special filename generation characters are always
+sensitive to case, thus restricting NO_CASE_GLOB to components that
+contain globbing characters.
+
+Note that if the filesystem itself is not sensitive to case, then
+CASE_PATHS has no effect.
+
+
+
+
+CSH_NULL_GLOB \
If a pattern for filename generation has no matches, delete the pattern
from the argument list; do not report an error unless all the patterns
-in a command have no matches. Overrides `NOMATCH`.
+in a command have no matches. Overrides NOMATCH.
-
-
+
-`EQUALS` \
+EQUALS \
-Perform `=` filename expansion. (See [Filename
+Perform = filename expansion. (See [Filename
Expansion](Expansion.html#Filename-Expansion).)
-
-
-
-
+
-`EXTENDED_GLOB`
+EXTENDED_GLOB
-Treat the ‘`#`’, ‘`~`’ and ‘`^`’ characters as part of patterns for
-filename generation, etc. (An initial unquoted ‘`~`’ always produces
-named directory expansion.)
+Treat the ‘#’, ‘\~’ and ‘^’ characters as part of patterns for filename
+generation, etc. (An initial unquoted ‘\~’ always produces named
+directory expansion.)
-
-
-
-
-
-
+
+
-`FORCE_FLOAT`
+FORCE_FLOAT
Constants in arithmetic evaluation will be treated as floating point
even without the use of a decimal point; the values of integer variables
will be converted to floating point when used in arithmetic expressions.
Integers in any base will be converted.
-
-
-
-
+
-`GLOB` (`+F`, ksh: `+f`) \
+GLOB (+F, ksh: +f) \
Perform filename generation (globbing). (See [Filename
Generation](Expansion.html#Filename-Generation).)
-
-
-
-
+
-`GLOB_ASSIGN` \
+GLOB_ASSIGN \
If this option is set, filename generation (globbing) is performed on
the right hand side of scalar parameter assignments of the form
-‘`name``=``pattern` (e.g. ‘`foo=*`’). If the result has more than one
-word the parameter will become an array with those words as arguments.
-This option is provided for backwards compatibility only: globbing is
-always performed on the right hand side of array assignments of the form
-‘`name``=(``value``)`’ (e.g. ‘`foo=(*)`’) and this form is recommended
-for clarity; with this option set, it is not possible to predict whether
-the result will be an array or a scalar.
+‘`name`=`pattern` (e.g. ‘foo=\*’). If the result has more than one word
+the parameter will become an array with those words as arguments. This
+option is provided for backwards compatibility only: globbing is always
+performed on the right hand side of array assignments of the form
+‘`name`=(`value`)’ (e.g. ‘foo=(\*)’) and this form is recommended for
+clarity; with this option set, it is not possible to predict whether the
+result will be an array or a scalar.
-
-
-
-
+
-`GLOB_DOTS` (`-4`)
+GLOB_DOTS (-4)
-Do not require a leading ‘`.`’ in a filename to be matched explicitly.
+Do not require a leading ‘.’ in a filename to be matched explicitly.
-
-
-
-
-
-
+
-`GLOB_STAR_SHORT`
+GLOB_STAR_SHORT
When this option is set and the default zsh-style globbing is in effect,
-the pattern ‘`**/*`’ can be abbreviated to ‘`**`’ and the pattern
-‘`***/*`’ can be abbreviated to `***`. Hence ‘`**.c`’ finds a file
-ending in `.c` in any subdirectory, and ‘`***.c`’ does the same while
-also following symbolic links. A `/` immediately after the ‘`**`’ or
-‘`***`’ forces the pattern to be treated as the unabbreviated form.
+the pattern ‘\*\*/\*’ can be abbreviated to ‘\*\*’ and the pattern
+‘\*\*\*/\*’ can be abbreviated to \*\*\*. Hence ‘\*\*.c’ finds a file
+ending in .c in any subdirectory, and ‘\*\*\*.c’ does the same while
+also following symbolic links. A / immediately after the ‘\*\*’ or
+‘\*\*\*’ forces the pattern to be treated as the unabbreviated form.
-
-
-
+
-`GLOB_SUBST` \ \ \
+GLOB_SUBST \ \ \
Treat any characters resulting from parameter expansion as being
eligible for filename expansion and filename generation, and any
@@ -684,52 +684,51 @@ characters resulting from command substitution as being eligible for
filename generation. Braces (and commas in between) do not become
eligible for expansion.
-
-
-
-
+
-`HIST_SUBST_PATTERN`
+HIST_SUBST_PATTERN
-Substitutions using the `:s` and `:&` history modifiers are performed
-with pattern matching instead of string matching. This occurs wherever
+Substitutions using the :s and :& history modifiers are performed with
+pattern matching instead of string matching. This occurs wherever
history modifiers are valid, including glob qualifiers and parameters.
See [Modifiers](Expansion.html#Modifiers).
-
-
-
-
-
-
-
+
+
-`IGNORE_BRACES` (`-I`) \
+IGNORE_BRACES (-I) \
Do not perform brace expansion. For historical reasons this also
-includes the effect of the `IGNORE_CLOSE_BRACES` option.
+includes the effect of the IGNORE_CLOSE_BRACES option.
-
-
-
-
+
-`IGNORE_CLOSE_BRACES`
+IGNORE_CLOSE_BRACES
-When neither this option nor `IGNORE_BRACES` is set, a sole close brace
-character ‘`}`’ is syntactically significant at any point on a command
+When neither this option nor IGNORE_BRACES is set, a sole close brace
+character ‘}’ is syntactically significant at any point on a command
line. This has the effect that no semicolon or newline is necessary
before the brace terminating a function or current shell construct. When
either option is set, a closing brace is syntactically significant only
-in command position. Unlike `IGNORE_BRACES`, this option does not
-disable brace expansion.
+in command position. Unlike IGNORE_BRACES, this option does not disable
+brace expansion.
For example, with both options unset a function may be defined in the
following fashion:
-``` example
+```zsh
args() { echo $# }
```
@@ -740,60 +739,61 @@ equivalent to the following is required:
-``` example
+```zsh
args() { echo $#; }
```
-
-
-
+
+
-`KSH_GLOB` \
+KSH_GLOB \
In pattern matching, the interpretation of parentheses is affected by a
-preceding ‘`@`’, ‘`*`’, ‘`+`’, ‘`?`’ or ‘`!`’. See [Filename
+preceding ‘@’, ‘\*’, ‘+’, ‘?’ or ‘!’. See [Filename
Generation](Expansion.html#Filename-Generation).
-
-
-
-
+
-`MAGIC_EQUAL_SUBST`
+MAGIC_EQUAL_SUBST
-All unquoted arguments of the form ‘`anything``=``expression`’ appearing
+All unquoted arguments of the form ‘`anything`=`expression`’ appearing
after the command name have filename expansion (that is, where
-`expression` has a leading ‘`~`’ or ‘`=`’) performed on `expression` as
-if it were a parameter assignment. The argument is not otherwise treated
+`expression` has a leading ‘\~’ or ‘=’) performed on `expression` as if
+it were a parameter assignment. The argument is not otherwise treated
specially; it is passed to the command as a single argument, and not
-used as an actual parameter assignment. For example, in `echo
-foo=~/bar:~/rod`, both occurrences of `~` would be replaced. Note that
-this happens anyway with `typeset` and similar statements.
+used as an actual parameter assignment. For example, in echo
+foo=\~/bar:\~/rod, both occurrences of \~ would be replaced. Note that
+this happens anyway with typeset and similar statements.
-This option respects the setting of the `KSH_TYPESET` option. In other
+This option respects the setting of the KSH_TYPESET option. In other
words, if both options are in effect, arguments looking like assignments
will not undergo word splitting.
-
-
-
-
-
+
-`MARK_DIRS` (`-8`, ksh: `-X`)
+MARK_DIRS (-8, ksh: -X)
-Append a trailing ‘`/`’ to all directory names resulting from filename
+Append a trailing ‘/’ to all directory names resulting from filename
generation (globbing).
-
-
-
-
-
+
+
+
-`MULTIBYTE` \
+MULTIBYTE \
Respect multibyte characters when found in strings. When this option is
set, strings are examined using the system library to determine how many
@@ -802,7 +802,7 @@ the way characters are counted in pattern matching, parameter values and
various delimiters.
The option is on by default if the shell was compiled with
-`MULTIBYTE_SUPPORT`; otherwise it is off by default and has no effect if
+MULTIBYTE_SUPPORT; otherwise it is off by default and has no effect if
turned on.
If the option is off a single byte is always treated as a single
@@ -817,134 +817,130 @@ locale to determine multibyte characters. This is because the character
set displayed by the terminal emulator is independent of shell settings.
-
-
+
-`NOMATCH` (`+3`) \ \
+NOMATCH (+3) \ \
If a pattern for filename generation has no matches, print an error,
instead of leaving it unchanged in the argument list. This also applies
-to file expansion of an initial ‘`~`’ or ‘`=`’.
+to file expansion of an initial ‘\~’ or ‘=’.
-
-
-
-
+
-`NULL_GLOB` (`-G`)
+NULL_GLOB (-G)
If a pattern for filename generation has no matches, delete the pattern
-from the argument list instead of reporting an error. Overrides
-`NOMATCH`.
+from the argument list instead of reporting an error. Overrides NOMATCH.
-
-
-
-
-
+
-`NUMERIC_GLOB_SORT`
+NUMERIC_GLOB_SORT
If numeric filenames are matched by a filename generation pattern, sort
the filenames numerically rather than lexicographically.
-
-
-
-
-
-
+
-`RC_EXPAND_PARAM` (`-P`)
+RC_EXPAND_PARAM (-P)
-Array expansions of the form ‘`foo``${``xx``}``bar`’, where the
-parameter `xx` is set to `(``a b c``)`, are substituted with ‘`fooabar
-foobbar foocbar`’ instead of the default ‘`fooa b cbar`’. Note that an
-empty array will therefore cause all arguments to be removed.
+Array expansions of the form ‘`foo`${`xx`}`bar`’, where the parameter
+`xx` is set to (`a b c`), are substituted with
+‘`fooabar foobbar foocbar`’ instead of the default ‘`fooa b cbar`’. Note
+that an empty array will therefore cause all arguments to be removed.
-
-
-
-
-
-
+
+
-`REMATCH_PCRE`
+REMATCH_PCRE
-If set, regular expression matching with the `=~` operator will use
-Perl-Compatible Regular Expressions from the PCRE library. (The
-`zsh/pcre` module must be available.) If not set, regular expressions
-will use the extended regexp syntax provided by the system libraries.
+If set, regular expression matching with the =\~ operator will use
+Perl-Compatible Regular Expressions from the PCRE library. (The zsh/pcre
+module must be available.) If not set, regular expressions will use the
+extended regexp syntax provided by the system libraries.
-
-
-
-
-
+
+
-`SH_GLOB` \ \
+SH_GLOB \ \
-Disables the special meaning of ‘`(`’, ‘`|`’, ‘`)`’ and ’`<`’ for
-globbing the result of parameter and command substitutions, and in some
-other places where the shell accepts patterns. If `SH_GLOB` is set but
-`KSH_GLOB` is not, the shell allows the interpretation of subshell
-expressions enclosed in parentheses in some cases where there is no
-space before the opening parenthesis, e.g. `!(true)` is interpreted as
-if there were a space after the `!`. This option is set by default if
-zsh is invoked as `sh` or `ksh`.
+Disables the special meaning of ‘(’, ‘\|’, ‘)’ and ’\<’ for globbing the
+result of parameter and command substitutions, and in some other places
+where the shell accepts patterns. If SH_GLOB is set but KSH_GLOB is not,
+the shell allows the interpretation of subshell expressions enclosed in
+parentheses in some cases where there is no space before the opening
+parenthesis, e.g. !(true) is interpreted as if there were a space after
+the !. This option is set by default if zsh is invoked as sh or ksh.
-
-
-
+
-`UNSET` (`+u`, ksh: `+u`) \ \ \
+UNSET (+u, ksh: +u) \ \ \
Treat unset parameters as if they were empty when substituting, and as
if they were zero when reading their values in arithmetic expansion and
arithmetic commands. Otherwise they are treated as an error.
-
-
-
-
-
+
-`WARN_CREATE_GLOBAL`
+WARN_CREATE_GLOBAL
Print a warning message when a global parameter is created in a function
by an assignment or in math context. This often indicates that a
parameter has not been declared local when it should have been.
Parameters explicitly declared global from within a function using
-`typeset -g` do not cause a warning. Note that there is no warning when
-a local parameter is assigned to in a nested function, which may also
+typeset -g do not cause a warning. Note that there is no warning when a
+local parameter is assigned to in a nested function, which may also
indicate an error.
-
-
-
-
-
+
-`WARN_NESTED_VAR`
+WARN_NESTED_VAR
Print a warning message when an existing parameter from an enclosing
function scope, or global, is set in a function by an assignment or in
math context. Assignment to shell special parameters does not cause a
-warning. This is the companion to `WARN_CREATE_GLOBAL` as in this case
-the warning is only printed when a parameter is *not* created. Where
-possible, use of `typeset -g` to set the parameter suppresses the error,
+warning. This is the companion to WARN_CREATE_GLOBAL as in this case the
+warning is only printed when a parameter is *not* created. Where
+possible, use of typeset -g to set the parameter suppresses the error,
but note that this needs to be used every time the parameter is set. To
restrict the effect of this option to a single function scope, use
-‘`functions -W`’.
+‘functions -W’.
For example, the following code produces a warning for the assignment
-inside the function `nested` as that overrides the value within
-`toplevel`
+inside the function nested as that overrides the value within toplevel
-``` example
+```zsh
toplevel() {
local foo="in fn"
nested
@@ -958,146 +954,146 @@ toplevel
------
+------------------------------------------------------------------------
### 16.2.4 History
-
-
-
-
-
+
-`APPEND_HISTORY` \
+APPEND_HISTORY \
If this is set, zsh sessions will append their history list to the
history file, rather than replace it. Thus, multiple parallel zsh
sessions will all have the new entries from their history lists added to
the history file, in the order that they exit. The file will still be
periodically re-written to trim it when the number of lines grows 20%
-beyond the value specified by `$SAVEHIST` (see also the
-`HIST_SAVE_BY_COPY` option).
+beyond the value specified by $SAVEHIST (see also the HIST_SAVE_BY_COPY
+option).
-
-
-
-
-
+
-`BANG_HIST` (`+K`) \ \
+BANG_HIST (+K) \ \
-Perform textual history expansion, csh-style, treating the character
-‘`!`’ specially.
+Perform textual history expansion, csh-style, treating the character ‘!’
+specially.
-
-
-
-
-
+
-`EXTENDED_HISTORY` \
+EXTENDED_HISTORY \
Save each command’s beginning timestamp (in seconds since the epoch) and
the duration (in seconds) to the history file. The format of this
prefixed data is:
-‘` : ````:````;```’.
+‘: ``:``;``’.
-
-
-
-
+
-`HIST_ALLOW_CLOBBER`
+HIST_ALLOW_CLOBBER
-Add ‘`|`’ to output redirections in the history. This allows history
-references to clobber files even when `CLOBBER` is unset.
+Add ‘\|’ to output redirections in the history. This allows history
+references to clobber files even when CLOBBER is unset.
-
-
-
-
-
+
-`HIST_BEEP` \
+HIST_BEEP \
Beep in ZLE when a widget attempts to access a history entry which isn’t
there.
-
-
-
-
-
+
-`HIST_EXPIRE_DUPS_FIRST`
+HIST_EXPIRE_DUPS_FIRST
If the internal history needs to be trimmed to add the current command
line, setting this option will cause the oldest history event that has a
duplicate to be lost before losing a unique event from the list. You
-should be sure to set the value of `HISTSIZE` to a larger number than
-`SAVEHIST` in order to give you some room for the duplicated events,
-otherwise this option will behave just like `HIST_IGNORE_ALL_DUPS` once
+should be sure to set the value of HISTSIZE to a larger number than
+SAVEHIST in order to give you some room for the duplicated events,
+otherwise this option will behave just like HIST_IGNORE_ALL_DUPS once
the history fills up with unique events.
-
-
-
-
+
-`HIST_FCNTL_LOCK`
+HIST_FCNTL_LOCK
When writing out the history file, by default zsh uses ad-hoc file
locking to avoid known problems with locking on some operating systems.
-With this option locking is done by means of the system’s `fcntl` call,
+With this option locking is done by means of the system’s fcntl call,
where this method is available. On recent operating systems this may
provide better performance, in particular avoiding history corruption
when files are stored on NFS.
-
-
-
-
-
+
-`HIST_FIND_NO_DUPS`
+HIST_FIND_NO_DUPS
When searching for history entries in the line editor, do not display
duplicates of a line previously found, even if the duplicates are not
contiguous.
-
-
-
-
-
+
-`HIST_IGNORE_ALL_DUPS`
+HIST_IGNORE_ALL_DUPS
If a new command line being added to the history list duplicates an
older one, the older command is removed from the list (even if it is not
the previous event).
-
-
-
-
-
+
-`HIST_IGNORE_DUPS` (`-h`)
+HIST_IGNORE_DUPS (-h)
Do not enter command lines into the history list if they are duplicates
of the previous event.
-
-
-
-
-
+
-`HIST_IGNORE_SPACE` (`-g`)
+HIST_IGNORE_SPACE (-g)
Remove command lines from the history list when the first character on
the line is a space, or when one of the expanded aliases contains a
@@ -1107,12 +1103,11 @@ until the next command is entered before it vanishes, allowing you to
briefly reuse or edit the line. If you want to make it vanish right away
without entering another command, type a space and press return.
-
-
-
-
+
-`HIST_LEX_WORDS`
+HIST_LEX_WORDS
By default, shell history that is read in from files is split into words
on all white space. This means that arguments with quoted whitespace are
@@ -1123,49 +1118,48 @@ a similar fashion to normal shell command line handling. Although this
produces more accurately delimited words, if the size of the history
file is large this can be slow. Trial and error is necessary to decide.
-
-
-
-
+
-`HIST_NO_FUNCTIONS`
+HIST_NO_FUNCTIONS
Remove function definitions from the history list. Note that the
function lingers in the internal history until the next command is
entered before it vanishes, allowing you to briefly reuse or edit the
definition.
-
-
-
-
+
-`HIST_NO_STORE`
+HIST_NO_STORE
-Remove the `history` (`fc -l`) command from the history list when
-invoked. Note that the command lingers in the internal history until the
-next command is entered before it vanishes, allowing you to briefly
-reuse or edit the line.
+Remove the history (fc -l) command from the history list when invoked.
+Note that the command lingers in the internal history until the next
+command is entered before it vanishes, allowing you to briefly reuse or
+edit the line.
-
-
-
-
+
-`HIST_REDUCE_BLANKS`
+HIST_REDUCE_BLANKS
Remove superfluous blanks from each command line being added to the
history list.
-
-
-
-
+
-`HIST_SAVE_BY_COPY` \
+HIST_SAVE_BY_COPY \
When the history file is re-written, we normally write out a copy of the
-file named `$HISTFILE.new` and then rename it over the old one. However,
+file named $HISTFILE.new and then rename it over the old one. However,
if this option is unset, we instead truncate the old history file and
write out the new version in-place. If one of the history-appending
options is enabled, this option only has an effect when the enlarged
@@ -1174,80 +1168,77 @@ this only if you have special needs, as doing so makes it possible to
lose history entries if zsh gets interrupted during the save.
When writing out a copy of the history file, zsh preserves the old
-file’s permissions and group information, but will refuse to write out
-a new file if it would change the history file’s owner.
+file’s permissions and group information, but will refuse to write out a
+new file if it would change the history file’s owner.
-
-
-
-
+
-`HIST_SAVE_NO_DUPS`
+HIST_SAVE_NO_DUPS
When writing out the history file, older commands that duplicate newer
ones are omitted.
-
-
-
-
+
-`HIST_VERIFY`
+HIST_VERIFY
Whenever the user enters a line with history expansion, don’t execute
the line directly; instead, perform history expansion and reload the
line into the editing buffer.
-
-
-
-
-
+
-`INC_APPEND_HISTORY`
+INC_APPEND_HISTORY
-This option works like `APPEND_HISTORY` except that new history lines
-are added to the `$HISTFILE` incrementally (as soon as they are
-entered), rather than waiting until the shell exits. The file will still
-be periodically re-written to trim it when the number of lines grows 20%
-beyond the value specified by `$SAVEHIST` (see also the
-`HIST_SAVE_BY_COPY` option).
+This option works like APPEND_HISTORY except that new history lines are
+added to the $HISTFILE incrementally (as soon as they are entered),
+rather than waiting until the shell exits. The file will still be
+periodically re-written to trim it when the number of lines grows 20%
+beyond the value specified by $SAVEHIST (see also the HIST_SAVE_BY_COPY
+option).
-
-
-
-
-
+
-`INC_APPEND_HISTORY_TIME`
+INC_APPEND_HISTORY_TIME
-This option is a variant of `INC_APPEND_HISTORY` in which, where
-possible, the history entry is written out to the file after the command
-is finished, so that the time taken by the command is recorded correctly
-in the history file in `EXTENDED_HISTORY` format. This means that the
-history entry will not be available immediately from other instances of
-the shell that are using the same history file.
+This option is a variant of INC_APPEND_HISTORY in which, where possible,
+the history entry is written out to the file after the command is
+finished, so that the time taken by the command is recorded correctly in
+the history file in EXTENDED_HISTORY format. This means that the history
+entry will not be available immediately from other instances of the
+shell that are using the same history file.
-This option is only useful if `INC_APPEND_HISTORY` and `SHARE_HISTORY`
-are turned off. The three options should be considered mutually
-exclusive.
+This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are
+turned off. The three options should be considered mutually exclusive.
-
-
-
-
-
-
+
+
-`SHARE_HISTORY` \
+SHARE_HISTORY \
This option both imports new commands from the history file, and also
causes your typed commands to be appended to the history file (the
-latter is like specifying `INC_APPEND_HISTORY`, which should be turned
-off if this option is in effect). The history lines are also output with
-timestamps ala `EXTENDED_HISTORY` (which makes it easier to find the
-spot where we left off reading the file after it gets re-written).
+latter is like specifying INC_APPEND_HISTORY, which should be turned off
+if this option is in effect). The history lines are also output with
+timestamps ala EXTENDED_HISTORY (which makes it easier to find the spot
+where we left off reading the file after it gets re-written).
By default, history movement commands visit the imported lines as well
as the local lines, but you can toggle this on and off with the
@@ -1256,249 +1247,259 @@ widget that will make some commands ignore imported commands, and some
include them.
If you find that you want more control over when commands get imported,
-you may wish to turn `SHARE_HISTORY` off, `INC_APPEND_HISTORY` or
-`INC_APPEND_HISTORY_TIME` (see above) on, and then manually import
-commands whenever you need them using ‘`fc -RI`’.
+you may wish to turn SHARE_HISTORY off, INC_APPEND_HISTORY or
+INC_APPEND_HISTORY_TIME (see above) on, and then manually import
+commands whenever you need them using ‘fc -RI’.
------
+------------------------------------------------------------------------
### 16.2.5 Initialisation
-
-
-
-
+
-`ALL_EXPORT` (`-a`, ksh: `-a`)
+ALL_EXPORT (-a, ksh: -a)
All parameters subsequently defined are automatically exported.
-
-
-
-
+
-`GLOBAL_EXPORT` \
+GLOBAL_EXPORT \
-If this option is set, passing the `-x` flag to the builtins `declare`,
-`float`, `integer`, `readonly` and `typeset` (but not `local`) will also
-set the `-g` flag; hence parameters exported to the environment will not
-be made local to the enclosing function, unless they were already or the
-flag `+g` is given explicitly. If the option is unset, exported
-parameters will be made local in just the same way as any other
-parameter.
+If this option is set, passing the -x flag to the builtins declare,
+float, integer, readonly and typeset (but not local) will also set the
+-g flag; hence parameters exported to the environment will not be made
+local to the enclosing function, unless they were already or the flag +g
+is given explicitly. If the option is unset, exported parameters will be
+made local in just the same way as any other parameter.
This option is set by default for backward compatibility; it is not
recommended that its behaviour be relied upon. Note that the builtin
-`export` always sets both the `-x` and `-g` flags, and hence its effect
+export always sets both the -x and -g flags, and hence its effect
extends beyond the scope of the enclosing function; this is the
-
-
-
-
-
-
+
-`GLOBAL_RCS` (`-d`) \
+GLOBAL_RCS (+d) \
-If this option is unset, the startup files `/etc/zprofile`,
-`/etc/zshrc`, `/etc/zlogin` and `/etc/zlogout` will not be run. It can
-be disabled and re-enabled at any time, including inside local startup
-files (`.zshrc`, etc.).
+If this option is unset, the startup files /etc/zprofile, /etc/zshrc,
+/etc/zlogin and /etc/zlogout will not be run. It can be disabled and
+re-enabled at any time, including inside local startup files (.zshrc,
+etc.).
-
-
-
+
-`RCS` (`+f`) \
+RCS (+f) \
-After `/etc/zshenv` is sourced on startup, source the `.zshenv`,
-`/etc/zprofile`, `.zprofile`, `/etc/zshrc`, `.zshrc`, `/etc/zlogin`,
-`.zlogin`, and `.zlogout` files, as described in
-[Files](Files.html#Files). If this option is unset, the `/etc/zshenv`
-file is still sourced, but any of the others will not be; it can be set
-at any time to prevent the remaining startup files after the currently
-executing one from being sourced.
+After /etc/zshenv is sourced on startup, source the .zshenv,
+/etc/zprofile, .zprofile, /etc/zshrc, .zshrc, /etc/zlogin, .zlogin, and
+.zlogout files, as described in [Files](Files.html#Files). If this
+option is unset, the /etc/zshenv file is still sourced, but any of the
+others will not be; it can be set at any time to prevent the remaining
+startup files after the currently executing one from being sourced.
------
+------------------------------------------------------------------------
### 16.2.6 Input/Output
-
-
+
-`ALIASES` \
+ALIASES \
Expand aliases.
-
-
-
+
-`CLOBBER` (`+C`, ksh: `+C`) \
+CLOBBER (+C, ksh: +C) \
-Allows ‘`>`’ redirection to truncate existing files. Otherwise ‘`>!`’ or
-‘`>|`’ must be used to truncate a file.
+Allows ‘>’ redirection to truncate existing files. Otherwise ‘>!’ or
+‘>\|’ must be used to truncate a file.
-If the option is not set, and the option `APPEND_CREATE` is also not
-set, ‘`>>!`’ or ‘`>>|`’ must be used to create a file. If either option
-is set, ‘`>>`’ may be used.
+If the option is not set, and the option APPEND_CREATE is also not set,
+‘>\>!’ or ‘>\>\|’ must be used to create a file. If either option is
+set, ‘>\>’ may be used.
+
+
+
+
+CLOBBER_EMPTY
+
+This option is only used if the option CLOBBER is not set: note that it
+is set by default.
+
+If this option is set, then regular files of zero length may be
+ovewritten (‘clobbered’). Note that it is possible another process has
+written to the file between this test and use of the file by the current
+process. This option should therefore not be used in cases where files
+to be clobbered may be written to asynchronously.
-
-
-
+
-`CORRECT` (`-0`)
+CORRECT (-0)
Try to correct the spelling of commands. Note that, when the
-`HASH_LIST_ALL` option is not set or when some directories in the path
-are not readable, this may falsely report spelling errors the first time
+HASH_LIST_ALL option is not set or when some directories in the path are
+not readable, this may falsely report spelling errors the first time
some commands are used.
-The shell variable `CORRECT_IGNORE` may be set to a pattern to match
-words that will never be offered as corrections.
+The shell variable CORRECT_IGNORE may be set to a pattern to match words
+that will never be offered as corrections.
-
-
-
-
+
-`CORRECT_ALL` (`-O`)
+CORRECT_ALL (-O)
Try to correct the spelling of all arguments in a line.
-The shell variable `CORRECT_IGNORE_FILE` may be set to a pattern to
-match file names that will never be offered as corrections.
+The shell variable CORRECT_IGNORE_FILE may be set to a pattern to match
+file names that will never be offered as corrections.
-`DVORAK`
+DVORAK
Use the Dvorak keyboard instead of the standard qwerty keyboard as a
-basis for examining spelling mistakes for the `CORRECT` and
-`CORRECT_ALL` options and the `spell-word` editor command.
+basis for examining spelling mistakes for the CORRECT and CORRECT_ALL
+options and the spell-word editor command.
-
-
-
-
+
-`FLOW_CONTROL` \
+FLOW_CONTROL \
If this option is unset, output flow control via start/stop characters
(usually assigned to ^S/^Q) is disabled in the shell’s editor.
-
-
-
-
+
-`IGNORE_EOF` (`-7`)
+IGNORE_EOF (-7)
-Do not exit on end-of-file. Require the use of `exit` or `logout`
-instead. However, ten consecutive EOFs will cause the shell to exit
-anyway, to avoid the shell hanging if its tty goes away.
+Do not exit on end-of-file. Require the use of exit or logout instead.
+However, ten consecutive EOFs will cause the shell to exit anyway, to
+avoid the shell hanging if its tty goes away.
Also, if this option is set and the Zsh Line Editor is used, widgets
implemented by shell functions can be bound to EOF (normally Control-D)
without printing the normal warning message. This works only for normal
widgets, not for completion widgets.
-
-
-
-
-
+
-`INTERACTIVE_COMMENTS` (`-k`) \ \
+INTERACTIVE_COMMENTS (-k) \ \
Allow comments even in interactive shells.
-
-
-
-
-
+
-`HASH_CMDS` \
+HASH_CMDS \
Note the location of each command the first time it is executed.
Subsequent invocations of the same command will use the saved location,
avoiding a path search. If this option is unset, no path hashing is done
-at all. However, when `CORRECT` is set, commands whose names do not
-appear in reporting them as spelling errors.
+at all. However, when CORRECT is set, commands whose names do not appear
+in reporting them as spelling errors.
-