Use zsh syntax in code blocks
This commit is contained in:
parent
e3ddbae998
commit
4faab81391
@ -107,5 +107,11 @@ system("rm -rf $cwd/zsh_manual/src") == 0 or die "$?";
|
||||
mkdir("$cwd/zsh_manual/src") or die "$?";
|
||||
system("cp $mdbook_src_dir/* $cwd/zsh_manual/src/") == 0 or die "$?";
|
||||
|
||||
# Replace ``` example with ```zsh for syntax highlighting
|
||||
@files = <$cwd/zsh_manual/src/*.md>;
|
||||
foreach my $file (@files) {
|
||||
system("sed -i 's/``` example/```zsh/g' '$file'") == 0 or die "$?";
|
||||
}
|
||||
|
||||
# Cleanup zsh_doc_tmp
|
||||
system("rm -rf $zsh_doc_tmp_dir") == 0 or die "$?";
|
||||
|
@ -6,40 +6,39 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Arithmetic-Evaluation"></span>
|
||||
<span id="Arithmetic-Evaluation-1"></span>
|
||||
<span id="Arithmetic-Evaluation"></span> <span
|
||||
id="Arithmetic-Evaluation-1"></span>
|
||||
|
||||
# 11 Arithmetic Evaluation
|
||||
|
||||
<span id="index-arithmetic-evaluation"></span>
|
||||
<span id="index-evaluation_002c-arithmetic"></span>
|
||||
<span id="index-let_002c-use-of"></span>
|
||||
<span id="index-arithmetic-evaluation"></span> <span
|
||||
id="index-evaluation_002c-arithmetic"></span> <span
|
||||
id="index-let_002c-use-of"></span>
|
||||
|
||||
The shell can perform integer and floating point arithmetic, either
|
||||
using the builtin `let`, or via a substitution of the form
|
||||
`$((``...``))`. For integers, the shell is usually compiled to use
|
||||
8-byte precision where this is available, otherwise precision is 4
|
||||
bytes. This can be tested, for example, by giving the command ‘`print -
|
||||
$(( 12345678901 ))`’; if the number appears unchanged, the precision is
|
||||
at least 8 bytes. Floating point arithmetic always uses the ‘double’
|
||||
type with whatever corresponding precision is provided by the compiler
|
||||
and the library.
|
||||
using the builtin let, or via a substitution of the form $((`...`)). For
|
||||
integers, the shell is usually compiled to use 8-byte precision where
|
||||
this is available, otherwise precision is 4 bytes. This can be tested,
|
||||
for example, by giving the command ‘print - $(( 12345678901 ))’; if the
|
||||
number appears unchanged, the precision is at least 8 bytes. Floating
|
||||
point arithmetic always uses the ‘double’ type with whatever
|
||||
corresponding precision is provided by the compiler and the library.
|
||||
|
||||
The `let` builtin command takes arithmetic expressions as arguments;
|
||||
each is evaluated separately. Since many of the arithmetic operators, as
|
||||
well as spaces, require quoting, an alternative form is provided: for
|
||||
any command which begins with a ‘`((`’, all the characters until a
|
||||
matching ‘`))`’ are treated as a quoted expression and arithmetic
|
||||
expansion performed as for an argument of `let`. More precisely,
|
||||
‘`((``...``))`’ is equivalent to ‘`let "``...``"`’. The return status
|
||||
is 0 if the arithmetic value of the expression is non-zero, 1 if it is
|
||||
zero, and 2 if an error occurred.
|
||||
The let builtin command takes arithmetic expressions as arguments; each
|
||||
is evaluated separately. Since many of the arithmetic operators, as well
|
||||
as spaces, require quoting, an alternative form is provided: for any
|
||||
command which begins with a ‘((’, all the characters until a matching
|
||||
‘))’ are treated as a double-quoted expression and arithmetic expansion
|
||||
performed as for an argument of let. More precisely, ‘((`...`))’ is
|
||||
equivalent to ‘let "`...`"’. The return status is 0 if the arithmetic
|
||||
value of the expression is non-zero, 1 if it is zero, and 2 if an error
|
||||
occurred.
|
||||
|
||||
For example, the following statement
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
(( val = 2 + 1 ))
|
||||
```
|
||||
|
||||
@ -49,39 +48,38 @@ is equivalent to
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
let "val = 2 + 1"
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
both assigning the value 3 to the shell variable `val` and returning a
|
||||
both assigning the value 3 to the shell variable val and returning a
|
||||
zero status.
|
||||
|
||||
<span id="index-arithmetic-base"></span>
|
||||
<span id="index-bases_002c-in-arithmetic"></span>
|
||||
<span id="index-arithmetic-base"></span> <span
|
||||
id="index-bases_002c-in-arithmetic"></span>
|
||||
|
||||
Integers can be in bases other than 10. A leading ‘`0x`’ or ‘`0X`’
|
||||
denotes hexadecimal and a leading ‘`0b`’ or ‘`0B`’ binary. Integers may
|
||||
also be of the form ‘`base``#``n`’, where `base` is a decimal number
|
||||
between two and thirty-six representing the arithmetic base and `n` is a
|
||||
number in that base (for example, ‘`16#ff`’ is 255 in hexadecimal). The
|
||||
`base``#` may also be omitted, in which case base 10 is used. For
|
||||
backwards compatibility the form ‘`[``base``]``n`’ is also accepted.
|
||||
Integers can be in bases other than 10. A leading ‘0x’ or ‘0X’ denotes
|
||||
hexadecimal and a leading ‘0b’ or ‘0B’ binary. Integers may also be of
|
||||
the form ‘`base`#`n`’, where `base` is a decimal number between two and
|
||||
thirty-six representing the arithmetic base and `n` is a number in that
|
||||
base (for example, ‘16#ff’ is 255 in hexadecimal). The `base`# may also
|
||||
be omitted, in which case base 10 is used. For backwards compatibility
|
||||
the form ‘\[`base`\]`n`’ is also accepted.
|
||||
|
||||
An integer expression or a base given in the form ‘`base``#``n`’ may
|
||||
contain underscores (‘`_`’) after the leading digit for visual guidance;
|
||||
these are ignored in computation. Examples are `1_000_000` or
|
||||
`0xffff_ffff` which are equivalent to `1000000` and `0xffffffff`
|
||||
respectively.
|
||||
An integer expression or a base given in the form ‘`base`#`n`’ may
|
||||
contain underscores (‘\_’) after the leading digit for visual guidance;
|
||||
these are ignored in computation. Examples are 1_000_000 or 0xffff_ffff
|
||||
which are equivalent to 1000000 and 0xffffffff respectively.
|
||||
|
||||
It is also possible to specify a base to be used for output in the form
|
||||
‘`[#``base``]`’, for example ‘`[#16]`’. This is used when outputting
|
||||
‘\[#`base`\]’, for example ‘\[#16\]’. This is used when outputting
|
||||
arithmetical substitutions or when assigning to scalar parameters, but
|
||||
an explicitly defined integer or floating point parameter will not be
|
||||
affected. If an integer variable is implicitly defined by an arithmetic
|
||||
expression, any base specified in this way will be set as the variable’s
|
||||
output arithmetic base as if the option ‘`-i` `base`’ to the `typeset`
|
||||
output arithmetic base as if the option ‘-i `base`’ to the typeset
|
||||
builtin had been used. The expression has no precedence and if it occurs
|
||||
more than once in a mathematical expression, the last encountered is
|
||||
used. For clarity it is recommended that it appear at the beginning of
|
||||
@ -89,7 +87,7 @@ an expression. As an example:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
typeset -i 16 y
|
||||
print $(( [#8] x = 32, y = 32 ))
|
||||
print $x $y
|
||||
@ -97,11 +95,10 @@ print $x $y
|
||||
|
||||
</div>
|
||||
|
||||
outputs first ‘`8#40`’, the rightmost value in the given output base,
|
||||
and then ‘`8#40 16#20`’, because `y` has been explicitly declared to
|
||||
have output base 16, while `x` (assuming it does not already exist) is
|
||||
implicitly typed by the arithmetic evaluation, where it acquires the
|
||||
output base 8.
|
||||
outputs first ‘8#40’, the rightmost value in the given output base, and
|
||||
then ‘8#40 16#20’, because y has been explicitly declared to have output
|
||||
base 16, while x (assuming it does not already exist) is implicitly
|
||||
typed by the arithmetic evaluation, where it acquires the output base 8.
|
||||
|
||||
The `base` may be replaced or followed by an underscore, which may
|
||||
itself be followed by a positive integer (if it is missing the value 3
|
||||
@ -111,14 +108,14 @@ integer specifies the number of digits to group together. For example:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
setopt cbases
|
||||
print $(( [#16_4] 65536 ** 2 ))
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
outputs ‘`0x1_0000_0000`’.
|
||||
outputs ‘0x1_0000_0000’.
|
||||
|
||||
The feature can be used with floating point numbers, in which case the
|
||||
base must be omitted; grouping is away from the decimal point. For
|
||||
@ -126,40 +123,40 @@ example,
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
zmodload zsh/mathfunc
|
||||
print $(( [#_] sqrt(1e7) ))
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
outputs ‘`3_162.277_660_168_379_5`’ (the number of decimal places shown
|
||||
outputs ‘3_162.277_660_168_379_5’ (the number of decimal places shown
|
||||
may vary).
|
||||
|
||||
<span id="index-C_005fBASES_002c-use-of"></span>
|
||||
<span id="index-OCTAL_005fZEROES_002c-use-of"></span>
|
||||
<span id="index-C_005fBASES_002c-use-of"></span> <span
|
||||
id="index-OCTAL_005fZEROES_002c-use-of"></span>
|
||||
|
||||
If the `C_BASES` option is set, hexadecimal numbers are output in the
|
||||
standard C format, for example ‘`0xFF`’ instead of the usual ‘`16#FF`’.
|
||||
If the option `OCTAL_ZEROES` is also set (it is not by default), octal
|
||||
numbers will be treated similarly and hence appear as ‘`077`’ instead of
|
||||
‘`8#77`’. This option has no effect on the output of bases other than
|
||||
If the C_BASES option is set, hexadecimal numbers are output in the
|
||||
standard C format, for example ‘0xFF’ instead of the usual ‘16#FF’. If
|
||||
the option OCTAL_ZEROES is also set (it is not by default), octal
|
||||
numbers will be treated similarly and hence appear as ‘077’ instead of
|
||||
‘8#77’. This option has no effect on the output of bases other than
|
||||
hexadecimal and octal, and these formats are always understood on input.
|
||||
|
||||
When an output base is specified using the ‘`[#``base``]`’ syntax, an
|
||||
When an output base is specified using the ‘\[#`base`\]’ syntax, an
|
||||
appropriate base prefix will be output if necessary, so that the value
|
||||
output is valid syntax for input. If the `#` is doubled, for example
|
||||
‘`[##16]`’, then no base prefix is output.
|
||||
output is valid syntax for input. If the # is doubled, for example
|
||||
‘\[##16\]’, then no base prefix is output.
|
||||
|
||||
Floating point constants are recognized by the presence of a decimal
|
||||
point or an exponent. The decimal point may be the first character of
|
||||
the constant, but the exponent character `e` or `E` may not, as it will
|
||||
be taken for a parameter name. All numeric parts (before and after the
|
||||
the constant, but the exponent character e or E may not, as it will be
|
||||
taken for a parameter name. All numeric parts (before and after the
|
||||
decimal point and in the exponent) may contain underscores after the
|
||||
leading digit for visual guidance; these are ignored in computation.
|
||||
|
||||
<span id="index-arithmetic-operators"></span>
|
||||
<span id="index-operators_002c-arithmetic"></span>
|
||||
<span id="index-arithmetic-operators"></span> <span
|
||||
id="index-operators_002c-arithmetic"></span>
|
||||
|
||||
An arithmetic expression uses nearly the same syntax and associativity
|
||||
of expressions as in C.
|
||||
@ -167,132 +164,132 @@ of expressions as in C.
|
||||
In the native mode of operation, the following operators are supported
|
||||
(listed in decreasing order of precedence):
|
||||
|
||||
- `+ - ! ~ ++ –`
|
||||
unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement
|
||||
\+ - ! \~ ++ –
|
||||
unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement
|
||||
|
||||
- `<< >>`
|
||||
bitwise shift left, right
|
||||
\<\< >\>
|
||||
bitwise shift left, right
|
||||
|
||||
- `&`
|
||||
bitwise AND
|
||||
&
|
||||
bitwise AND
|
||||
|
||||
- `^`
|
||||
bitwise XOR
|
||||
^
|
||||
bitwise XOR
|
||||
|
||||
- `|`
|
||||
bitwise OR
|
||||
\|
|
||||
bitwise OR
|
||||
|
||||
- `**`
|
||||
exponentiation
|
||||
\*\*
|
||||
exponentiation
|
||||
|
||||
- `* / %`
|
||||
multiplication, division, modulus (remainder)
|
||||
\* / %
|
||||
multiplication, division, modulus (remainder)
|
||||
|
||||
- `+ -`
|
||||
addition, subtraction
|
||||
\+ -
|
||||
addition, subtraction
|
||||
|
||||
- `< > <= >=`
|
||||
comparison
|
||||
\< > \<= >=
|
||||
comparison
|
||||
|
||||
- `== !=`
|
||||
equality and inequality
|
||||
== !=
|
||||
equality and inequality
|
||||
|
||||
- `&&`
|
||||
logical AND
|
||||
&&
|
||||
logical AND
|
||||
|
||||
- `|| ^^`
|
||||
logical OR, XOR
|
||||
\|\| ^^
|
||||
logical OR, XOR
|
||||
|
||||
- `? :`
|
||||
ternary operator
|
||||
? :
|
||||
ternary operator
|
||||
|
||||
- `= += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **=`
|
||||
assignment
|
||||
= += -= \*= /= %= &= ^= \|= \<\<= >\>= &&= \|\|= ^^= \*\*=
|
||||
assignment
|
||||
|
||||
- `,`
|
||||
comma operator
|
||||
,
|
||||
comma operator
|
||||
|
||||
The operators ‘`&&`’, ‘`||`’, ‘`&&=`’, and ‘`||=`’ are short-circuiting,
|
||||
and only one of the latter two expressions in a ternary operator is
|
||||
The operators ‘&&’, ‘\|\|’, ‘&&=’, and ‘\|\|=’ are short-circuiting, and
|
||||
only one of the latter two expressions in a ternary operator is
|
||||
evaluated. Note the precedence of the bitwise AND, OR, and XOR
|
||||
operators.
|
||||
|
||||
With the option `C_PRECEDENCES` the precedences (but no other
|
||||
properties) of the operators are altered to be the same as those in most
|
||||
other languages that support the relevant operators:
|
||||
With the option C_PRECEDENCES the precedences (but no other properties)
|
||||
of the operators are altered to be the same as those in most other
|
||||
languages that support the relevant operators:
|
||||
|
||||
- `+ - ! ~ ++ –`
|
||||
unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement
|
||||
\+ - ! \~ ++ –
|
||||
unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement
|
||||
|
||||
- `**`
|
||||
exponentiation
|
||||
\*\*
|
||||
exponentiation
|
||||
|
||||
- `* / %`
|
||||
multiplication, division, modulus (remainder)
|
||||
\* / %
|
||||
multiplication, division, modulus (remainder)
|
||||
|
||||
- `+ -`
|
||||
addition, subtraction
|
||||
\+ -
|
||||
addition, subtraction
|
||||
|
||||
- `<< >>`
|
||||
bitwise shift left, right
|
||||
\<\< >\>
|
||||
bitwise shift left, right
|
||||
|
||||
- `< > <= >=`
|
||||
comparison
|
||||
\< > \<= >=
|
||||
comparison
|
||||
|
||||
- `== !=`
|
||||
equality and inequality
|
||||
== !=
|
||||
equality and inequality
|
||||
|
||||
- `&`
|
||||
bitwise AND
|
||||
&
|
||||
bitwise AND
|
||||
|
||||
- `^`
|
||||
bitwise XOR
|
||||
^
|
||||
bitwise XOR
|
||||
|
||||
- `|`
|
||||
bitwise OR
|
||||
\|
|
||||
bitwise OR
|
||||
|
||||
- `&&`
|
||||
logical AND
|
||||
&&
|
||||
logical AND
|
||||
|
||||
- `^^`
|
||||
logical XOR
|
||||
^^
|
||||
logical XOR
|
||||
|
||||
- `||`
|
||||
logical OR
|
||||
\|\|
|
||||
logical OR
|
||||
|
||||
- `? :`
|
||||
ternary operator
|
||||
? :
|
||||
ternary operator
|
||||
|
||||
- `= += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **=`
|
||||
assignment
|
||||
= += -= \*= /= %= &= ^= \|= \<\<= >\>= &&= \|\|= ^^= \*\*=
|
||||
assignment
|
||||
|
||||
- `,`
|
||||
comma operator
|
||||
,
|
||||
comma operator
|
||||
|
||||
Note the precedence of exponentiation in both cases is below that of
|
||||
unary operators, hence ‘`-3**2`’ evaluates as ‘`9`’, not ‘`-9`’. Use
|
||||
parentheses where necessary: ‘`-(3**2)`’. This is for compatibility with
|
||||
unary operators, hence ‘-3\*\*2’ evaluates as ‘9’, not ‘-9’. Use
|
||||
parentheses where necessary: ‘-(3\*\*2)’. This is for compatibility with
|
||||
other shells.
|
||||
|
||||
<span id="index-mathematical-functions_002c-use-of"></span>
|
||||
<span id="index-functions_002c-math_002c-use-of"></span>
|
||||
<span id="index-mathematical-functions_002c-use-of"></span> <span
|
||||
id="index-functions_002c-math_002c-use-of"></span>
|
||||
|
||||
Mathematical functions can be called with the syntax
|
||||
‘`func``(``args``)`’, where the function decides if the `args` is
|
||||
used as a string or a comma-separated list of arithmetic expressions.
|
||||
The shell currently defines no mathematical functions by default, but
|
||||
the module `zsh/mathfunc` may be loaded with the `zmodload` builtin to
|
||||
provide standard floating point mathematical functions.
|
||||
Mathematical functions can be called with the syntax ‘`func`(`args`)’,
|
||||
where the function decides if the `args` is used as a string or a
|
||||
comma-separated list of arithmetic expressions. The shell currently
|
||||
defines no mathematical functions by default, but the module
|
||||
zsh/mathfunc may be loaded with the zmodload builtin to provide standard
|
||||
floating point mathematical functions.
|
||||
|
||||
An expression of the form ‘`##``x`’ where `x` is any character sequence
|
||||
such as ‘`a`’, ‘`^A`’, or ‘`\M-\C-x`’ gives the value of this character
|
||||
and an expression of the form ‘`#``name`’ gives the value of the first
|
||||
An expression of the form ‘##`x`’ where `x` is any character sequence
|
||||
such as ‘a’, ‘^A’, or ‘\\M-\\C-x’ gives the value of this character and
|
||||
an expression of the form ‘#`name`’ gives the value of the first
|
||||
character of the contents of the parameter `name`. Character values are
|
||||
according to the character set used in the current locale; for multibyte
|
||||
character handling the option `MULTIBYTE` must be set. Note that this
|
||||
form is different from ‘`$#``name`’, a standard parameter substitution
|
||||
which gives the length of the parameter `name`. ‘`#\`’ is accepted
|
||||
instead of ‘`##`’, but its use is deprecated.
|
||||
character handling the option MULTIBYTE must be set. Note that this form
|
||||
is different from ‘$#`name`’, a standard parameter substitution which
|
||||
gives the length of the parameter `name`. ‘#\\’ is accepted instead of
|
||||
‘##’, but its use is deprecated.
|
||||
|
||||
Named parameters and subscripted arrays can be referenced by name within
|
||||
an arithmetic expression without using the parameter expansion syntax.
|
||||
@ -300,46 +297,46 @@ For example,
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
((val2 = val1 * 2))
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
assigns twice the value of `$val1` to the parameter named `val2`.
|
||||
assigns twice the value of $val1 to the parameter named val2.
|
||||
|
||||
An internal integer representation of a named parameter can be specified
|
||||
with the `integer` builtin.
|
||||
<span id="index-parameters_002c-integer"></span>
|
||||
<span id="index-integer-parameters"></span>
|
||||
<span id="index-integer_002c-use-of"></span> Arithmetic evaluation is
|
||||
with the integer builtin. <span
|
||||
id="index-parameters_002c-integer"></span> <span
|
||||
id="index-integer-parameters"></span> <span
|
||||
id="index-integer_002c-use-of"></span> Arithmetic evaluation is
|
||||
performed on the value of each assignment to a named parameter declared
|
||||
integer in this manner. Assigning a floating point number to an integer
|
||||
results in rounding towards zero.
|
||||
|
||||
<span id="index-parameters_002c-floating-point"></span>
|
||||
<span id="index-floating-point-parameters"></span>
|
||||
<span id="index-float_002c-use-of"></span>
|
||||
<span id="index-parameters_002c-floating-point"></span> <span
|
||||
id="index-floating-point-parameters"></span> <span
|
||||
id="index-float_002c-use-of"></span>
|
||||
|
||||
Likewise, floating point numbers can be declared with the `float`
|
||||
builtin; there are two types, differing only in their output format, as
|
||||
described for the `typeset` builtin. The output format can be bypassed
|
||||
by using arithmetic substitution instead of the parameter substitution,
|
||||
i.e. ‘`${``float``}`’ uses the defined format, but ‘`$((``float``))`’
|
||||
uses a generic floating point format.
|
||||
Likewise, floating point numbers can be declared with the float builtin;
|
||||
there are two types, differing only in their output format, as described
|
||||
for the typeset builtin. The output format can be bypassed by using
|
||||
arithmetic substitution instead of the parameter substitution, i.e.
|
||||
‘${`float`}’ uses the defined format, but ‘$((`float`))’ uses a generic
|
||||
floating point format.
|
||||
|
||||
Promotion of integer to floating point values is performed where
|
||||
necessary. In addition, if any operator which requires an integer
|
||||
(‘`&`’, ‘`|`’, ‘`^`’, ‘`<<`’, ‘`>>`’ and their equivalents with
|
||||
assignment) is given a floating point argument, it will be silently
|
||||
rounded towards zero except for ‘`~`’ which rounds down.
|
||||
necessary. In addition, if any operator which requires an integer (‘&’,
|
||||
‘\|’, ‘^’, ‘\<\<’, ‘>\>’ and their equivalents with assignment) is given
|
||||
a floating point argument, it will be silently rounded towards zero
|
||||
except for ‘\~’ which rounds down.
|
||||
|
||||
Users should beware that, in common with many other programming
|
||||
languages but not software designed for calculation, the evaluation of
|
||||
an expression in zsh is taken a term at a time and promotion of integers
|
||||
to floating point does not occur in terms only containing integers. A
|
||||
typical result of this is that a division such as `6/8` is truncated, in
|
||||
this being rounded towards 0. The `FORCE_FLOAT` shell option can be used
|
||||
typical result of this is that a division such as 6/8 is truncated, in
|
||||
this being rounded towards 0. The FORCE_FLOAT shell option can be used
|
||||
in scripts or functions where floating point evaluation is required
|
||||
throughout.
|
||||
|
||||
@ -347,14 +344,14 @@ Scalar variables can hold integer or floating point values at different
|
||||
times; there is no memory of the numeric type in this case.
|
||||
|
||||
If a variable is first assigned in a numeric context without previously
|
||||
being declared, it will be implicitly typed as `integer` or `float` and
|
||||
being declared, it will be implicitly typed as integer or float and
|
||||
retain that type either until the type is explicitly changed or until
|
||||
the end of the scope. This can have unforeseen consequences. For
|
||||
example, in the loop
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
for (( f = 0; f < 1; f += 0.1 )); do
|
||||
# use $f
|
||||
done
|
||||
@ -362,15 +359,15 @@ done
|
||||
|
||||
</div>
|
||||
|
||||
if `f` has not already been declared, the first assignment will cause it
|
||||
to be created as an integer, and consequently the operation ‘`f += 0.1`’
|
||||
if f has not already been declared, the first assignment will cause it
|
||||
to be created as an integer, and consequently the operation ‘f += 0.1’
|
||||
will always cause the result to be truncated to zero, so that the loop
|
||||
will fail. A simple fix would be to turn the initialization into ‘`f
|
||||
= 0.0`’. It is therefore best to declare numeric variables with explicit
|
||||
will fail. A simple fix would be to turn the initialization into ‘f =
|
||||
0.0’. It is therefore best to declare numeric variables with explicit
|
||||
types.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,15 +6,15 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Command-Execution"></span>
|
||||
<span id="Command-Execution-1"></span>
|
||||
<span id="Command-Execution"></span> <span
|
||||
id="Command-Execution-1"></span>
|
||||
|
||||
# 8 Command Execution
|
||||
|
||||
<span id="index-command-execution"></span>
|
||||
<span id="index-execution_002c-of-commands"></span>
|
||||
<span id="index-command-not-found_002c-handling-of"></span>
|
||||
<span id="index-command_005fnot_005ffound_005fhandler"></span>
|
||||
<span id="index-command-execution"></span> <span
|
||||
id="index-execution_002c-of-commands"></span> <span
|
||||
id="index-command-not-found_002c-handling-of"></span> <span
|
||||
id="index-command_005fnot_005ffound_005fhandler"></span>
|
||||
|
||||
If a command name contains no slashes, the shell attempts to locate it.
|
||||
If there exists a shell function by that name, the function is invoked
|
||||
@ -23,28 +23,37 @@ shell builtin by that name, the builtin is invoked.
|
||||
|
||||
<span id="index-path_002c-use-of"></span>
|
||||
|
||||
Otherwise, the shell searches each element of `$path` for a search is
|
||||
unsuccessful, the shell prints an error message and returns a nonzero
|
||||
exit status.
|
||||
Otherwise, the shell searches each element of $path for a
|
||||
|
||||
If execution fails: an error message is printed, and one of the
|
||||
following values is returned.
|
||||
|
||||
127
|
||||
|
||||
The search was unsuccessful. The error message is ‘command not found:
|
||||
`cmd`’.
|
||||
|
||||
126
|
||||
|
||||
directory or special file, or is not a script and is in a format
|
||||
unrecognized by the operating system. The exact conditions and error
|
||||
message are operating system-dependent; see execve(2).
|
||||
|
||||
and the file is not a directory, it is assumed to be a shell script.
|
||||
`/bin/sh` is spawned to execute it. If the program is a file beginning
|
||||
with ‘`#!`’, the remainder of the first line specifies an interpreter
|
||||
for the program. The shell will execute the specified interpreter on
|
||||
/bin/sh is spawned to execute it. If the program is a file beginning
|
||||
with ‘#!’, the remainder of the first line specifies an interpreter for
|
||||
the program. The shell will execute the specified interpreter on
|
||||
operating systems that do
|
||||
|
||||
If no external command is found but a function
|
||||
`command_not_found_handler` exists the shell executes this function with
|
||||
all command line arguments. The return status of the function becomes
|
||||
the status of the command. If the function wishes to mimic the behaviour
|
||||
of the shell when the command is not found, it should print the message
|
||||
‘`command not found:` `cmd`’ to standard error and return status 127.
|
||||
If no external command is found but a function command_not_found_handler
|
||||
exists the shell executes this function with all command line arguments.
|
||||
The return status of the function becomes the status of the command.
|
||||
Note that the handler is executed in a subshell forked to execute an
|
||||
external command, hence changes to directories, shell parameters, etc.
|
||||
have no effect on the main shell.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -6,198 +6,195 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Conditional-Expressions"></span>
|
||||
<span id="Conditional-Expressions-1"></span>
|
||||
<span id="Conditional-Expressions"></span> <span
|
||||
id="Conditional-Expressions-1"></span>
|
||||
|
||||
# 12 Conditional Expressions
|
||||
|
||||
<span id="index-conditional-expressions"></span>
|
||||
<span id="index-expressions_002c-conditional"></span>
|
||||
<span id="index-conditional-expressions"></span> <span
|
||||
id="index-expressions_002c-conditional"></span>
|
||||
|
||||
A *conditional expression* is used with the `[[` compound command to
|
||||
A *conditional expression* is used with the \[\[ compound command to
|
||||
test attributes of files and to compare strings. Each expression can be
|
||||
constructed from one or more of the following unary or binary
|
||||
expressions:
|
||||
|
||||
- `-a` `file`
|
||||
true if `file` exists.
|
||||
-a `file`
|
||||
true if `file` exists.
|
||||
|
||||
- `-b` `file`
|
||||
true if `file` exists and is a block special file.
|
||||
-b `file`
|
||||
true if `file` exists and is a block special file.
|
||||
|
||||
- `-c` `file`
|
||||
true if `file` exists and is a character special file.
|
||||
-c `file`
|
||||
true if `file` exists and is a character special file.
|
||||
|
||||
- `-d` `file`
|
||||
true if `file` exists and is a directory.
|
||||
-d `file`
|
||||
true if `file` exists and is a directory.
|
||||
|
||||
- `-e` `file`
|
||||
true if `file` exists.
|
||||
-e `file`
|
||||
true if `file` exists.
|
||||
|
||||
- `-f` `file`
|
||||
true if `file` exists and is a regular file.
|
||||
-f `file`
|
||||
true if `file` exists and is a regular file.
|
||||
|
||||
- `-g` `file`
|
||||
true if `file` exists and has its setgid bit set.
|
||||
-g `file`
|
||||
true if `file` exists and has its setgid bit set.
|
||||
|
||||
- `-h` `file`
|
||||
true if `file` exists and is a symbolic link.
|
||||
-h `file`
|
||||
true if `file` exists and is a symbolic link.
|
||||
|
||||
- `-k` `file`
|
||||
true if `file` exists and has its sticky bit set.
|
||||
-k `file`
|
||||
true if `file` exists and has its sticky bit set.
|
||||
|
||||
- `-n` `string`
|
||||
true if length of `string` is non-zero.
|
||||
-n `string`
|
||||
true if length of `string` is non-zero.
|
||||
|
||||
- `-o` `option`
|
||||
true if option named `option` is on. `option` may be a single
|
||||
character, in which case it is a single letter option name. (See
|
||||
[Specifying Options](Options.html#Specifying-Options).)
|
||||
-o `option`
|
||||
true if option named `option` is on. `option` may be a single character,
|
||||
in which case it is a single letter option name. (See [Specifying
|
||||
Options](Options.html#Specifying-Options).)
|
||||
|
||||
When no option named `option` exists, and the `POSIX_BUILTINS`
|
||||
option hasn’t been set, return 3 with a warning. If that option is
|
||||
set, return 1 with no warning.
|
||||
When no option named `option` exists, and the POSIX_BUILTINS option
|
||||
hasn’t been set, return 3 with a warning. If that option is set, return
|
||||
1 with no warning.
|
||||
|
||||
- `-p` `file`
|
||||
true if `file` exists and is a FIFO special file (named pipe).
|
||||
-p `file`
|
||||
true if `file` exists and is a FIFO special file (named pipe).
|
||||
|
||||
- `-r` `file`
|
||||
true if `file` exists and is readable by current process.
|
||||
-r `file`
|
||||
true if `file` exists and is readable by current process.
|
||||
|
||||
- `-s` `file`
|
||||
true if `file` exists and has size greater than zero.
|
||||
-s `file`
|
||||
true if `file` exists and has size greater than zero.
|
||||
|
||||
- `-t` `fd`
|
||||
true if file descriptor number `fd` is open and associated with a
|
||||
terminal device. (note: `fd` is not optional)
|
||||
-t `fd`
|
||||
true if file descriptor number `fd` is open and associated with a
|
||||
terminal device. (note: `fd` is not optional)
|
||||
|
||||
- `-u` `file`
|
||||
true if `file` exists and has its setuid bit set.
|
||||
-u `file`
|
||||
true if `file` exists and has its setuid bit set.
|
||||
|
||||
- `-v` `varname`
|
||||
true if shell variable `varname` is set.
|
||||
-v `varname`
|
||||
true if shell variable `varname` is set.
|
||||
|
||||
- `-w` `file`
|
||||
`-x` `file`
|
||||
`-z` `string`
|
||||
true if length of `string` is zero.
|
||||
-w `file`
|
||||
-x `file`
|
||||
-z `string`
|
||||
true if length of `string` is zero.
|
||||
|
||||
- `-L` `file`
|
||||
true if `file` exists and is a symbolic link.
|
||||
-L `file`
|
||||
true if `file` exists and is a symbolic link.
|
||||
|
||||
- `-O` `file`
|
||||
true if `file` exists and is owned by the effective user ID of this
|
||||
process.
|
||||
-O `file`
|
||||
true if `file` exists and is owned by the effective user ID of this
|
||||
process.
|
||||
|
||||
- `-G` `file`
|
||||
true if `file` exists and its group matches the effective group ID
|
||||
of this process.
|
||||
-G `file`
|
||||
true if `file` exists and its group matches the effective group ID of
|
||||
this process.
|
||||
|
||||
- `-S` `file`
|
||||
true if `file` exists and is a socket.
|
||||
-S `file`
|
||||
true if `file` exists and is a socket.
|
||||
|
||||
- `-N` `file`
|
||||
true if `file` exists and its access time is not newer than its
|
||||
modification time.
|
||||
-N `file`
|
||||
true if `file` exists and its access time is not newer than its
|
||||
modification time.
|
||||
|
||||
- `file1` `-nt` `file2`
|
||||
true if `file1` exists and is newer than `file2`.
|
||||
`file1` -nt `file2`
|
||||
true if `file1` exists and is newer than `file2`.
|
||||
|
||||
- `file1` `-ot` `file2`
|
||||
true if `file1` exists and is older than `file2`.
|
||||
`file1` -ot `file2`
|
||||
true if `file1` exists and is older than `file2`.
|
||||
|
||||
- `file1` `-ef` `file2`
|
||||
true if `file1` and `file2` exist and refer to the same file.
|
||||
`file1` -ef `file2`
|
||||
true if `file1` and `file2` exist and refer to the same file.
|
||||
|
||||
- `string` `=` `pattern`
|
||||
`string` `==` `pattern`
|
||||
true if `string` matches `pattern`. The two forms are exactly
|
||||
equivalent. The ‘`=`’ form is the traditional shell syntax (and
|
||||
hence the only one generally used with the `test` and `[` builtins);
|
||||
the ‘`==`’ form provides compatibility with other sorts of computer
|
||||
language.
|
||||
`string` = `pattern`
|
||||
`string` == `pattern`
|
||||
true if `string` matches `pattern`. The two forms are exactly
|
||||
equivalent. The ‘=’ form is the traditional shell syntax (and hence the
|
||||
only one generally used with the test and \[ builtins); the ‘==’ form
|
||||
provides compatibility with other sorts of computer language.
|
||||
|
||||
- `string` `!=` `pattern`
|
||||
true if `string` does not match `pattern`.
|
||||
`string` != `pattern`
|
||||
true if `string` does not match `pattern`.
|
||||
|
||||
- `string` `=~` `regexp`
|
||||
true if `string` matches the regular expression `regexp`. If the
|
||||
option `RE_MATCH_PCRE` is set `regexp` is tested as a PCRE regular
|
||||
expression using the `zsh/pcre` module, else it is tested as a POSIX
|
||||
extended regular expression using the `zsh/regex` module. Upon
|
||||
successful match, some variables will be updated; no variables are
|
||||
changed if the matching fails.
|
||||
`string` =\~ `regexp`
|
||||
true if `string` matches the regular expression `regexp`. If the option
|
||||
RE_MATCH_PCRE is set `regexp` is tested as a PCRE regular expression
|
||||
using the zsh/pcre module, else it is tested as a POSIX extended regular
|
||||
expression using the zsh/regex module. Upon successful match, some
|
||||
variables will be updated; no variables are changed if the matching
|
||||
fails.
|
||||
|
||||
If the option `BASH_REMATCH` is not set the scalar parameter `MATCH`
|
||||
is set to the substring that matched the pattern and the integer
|
||||
parameters `MBEGIN` and `MEND` to the index of the start and end,
|
||||
respectively, of the match in `string`, such that if `string` is
|
||||
contained in variable `var` the expression ‘`${var[$MBEGIN,$MEND]}`’
|
||||
is identical to ‘`$MATCH`’. The setting of the option `KSH_ARRAYS`
|
||||
is respected. Likewise, the array `match` is set to the substrings
|
||||
that matched parenthesised subexpressions and the arrays `mbegin`
|
||||
and `mend` to the indices of the start and end positions,
|
||||
respectively, of the substrings within `string`. The arrays are not
|
||||
set if there were no parenthesised subexpressions. For example, if
|
||||
the string ‘`a short string`’ is matched against the regular
|
||||
expression ‘`s(...)t`’, then (assuming the option `KSH_ARRAYS` is
|
||||
not set) `MATCH`, `MBEGIN` and `MEND` are ‘`short`’, `3` and `7`,
|
||||
respectively, while `match`, `mbegin` and `mend` are single entry
|
||||
arrays containing the strings ‘`hor`’, ‘`4`’ and ‘`6`’,
|
||||
respectively.
|
||||
If the option BASH_REMATCH is not set the scalar parameter MATCH is set
|
||||
to the substring that matched the pattern and the integer parameters
|
||||
MBEGIN and MEND to the index of the start and end, respectively, of the
|
||||
match in `string`, such that if `string` is contained in variable var
|
||||
the expression ‘${var\[$MBEGIN,$MEND\]}’ is identical to ‘$MATCH’. The
|
||||
setting of the option KSH_ARRAYS is respected. Likewise, the array match
|
||||
is set to the substrings that matched parenthesised subexpressions and
|
||||
the arrays mbegin and mend to the indices of the start and end
|
||||
positions, respectively, of the substrings within `string`. The arrays
|
||||
are not set if there were no parenthesised subexpressions. For example,
|
||||
if the string ‘a short string’ is matched against the regular expression
|
||||
‘s(...)t’, then (assuming the option KSH_ARRAYS is not set) MATCH,
|
||||
MBEGIN and MEND are ‘short’, 3 and 7, respectively, while match, mbegin
|
||||
and mend are single entry arrays containing the strings ‘hor’, ‘4’ and
|
||||
‘6’, respectively.
|
||||
|
||||
If the option `BASH_REMATCH` is set the array `BASH_REMATCH` is set
|
||||
to the substring that matched the pattern followed by the substrings
|
||||
that matched parenthesised subexpressions within the pattern.
|
||||
If the option BASH_REMATCH is set the array BASH_REMATCH is set to the
|
||||
substring that matched the pattern followed by the substrings that
|
||||
matched parenthesised subexpressions within the pattern.
|
||||
|
||||
- `string1` `<` `string2`
|
||||
true if `string1` comes before `string2` based on ASCII value of
|
||||
their characters.
|
||||
`string1` \< `string2`
|
||||
true if `string1` comes before `string2` based on ASCII value of their
|
||||
characters.
|
||||
|
||||
- `string1` `>` `string2`
|
||||
true if `string1` comes after `string2` based on ASCII value of
|
||||
their characters.
|
||||
`string1` > `string2`
|
||||
true if `string1` comes after `string2` based on ASCII value of their
|
||||
characters.
|
||||
|
||||
- `exp1` `-eq` `exp2`
|
||||
true if `exp1` is numerically equal to `exp2`. Note that for purely
|
||||
numeric comparisons use of the `((``...``))` builtin described in
|
||||
[Arithmetic
|
||||
Evaluation](Arithmetic-Evaluation.html#Arithmetic-Evaluation) is
|
||||
more convenient than conditional expressions.
|
||||
`exp1` -eq `exp2`
|
||||
true if `exp1` is numerically equal to `exp2`. Note that for purely
|
||||
numeric comparisons use of the ((`...`)) builtin described in
|
||||
[Arithmetic
|
||||
Evaluation](Arithmetic-Evaluation.html#Arithmetic-Evaluation) is more
|
||||
convenient than conditional expressions.
|
||||
|
||||
- `exp1` `-ne` `exp2`
|
||||
true if `exp1` is numerically not equal to `exp2`.
|
||||
`exp1` -ne `exp2`
|
||||
true if `exp1` is numerically not equal to `exp2`.
|
||||
|
||||
- `exp1` `-lt` `exp2`
|
||||
true if `exp1` is numerically less than `exp2`.
|
||||
`exp1` -lt `exp2`
|
||||
true if `exp1` is numerically less than `exp2`.
|
||||
|
||||
- `exp1` `-gt` `exp2`
|
||||
true if `exp1` is numerically greater than `exp2`.
|
||||
`exp1` -gt `exp2`
|
||||
true if `exp1` is numerically greater than `exp2`.
|
||||
|
||||
- `exp1` `-le` `exp2`
|
||||
true if `exp1` is numerically less than or equal to `exp2`.
|
||||
`exp1` -le `exp2`
|
||||
true if `exp1` is numerically less than or equal to `exp2`.
|
||||
|
||||
- `exp1` `-ge` `exp2`
|
||||
true if `exp1` is numerically greater than or equal to `exp2`.
|
||||
`exp1` -ge `exp2`
|
||||
true if `exp1` is numerically greater than or equal to `exp2`.
|
||||
|
||||
- `(` `exp` `)`
|
||||
true if `exp` is true.
|
||||
( `exp` )
|
||||
true if `exp` is true.
|
||||
|
||||
- `!` `exp`
|
||||
true if `exp` is false.
|
||||
! `exp`
|
||||
true if `exp` is false.
|
||||
|
||||
- `exp1` `&&` `exp2`
|
||||
true if `exp1` and `exp2` are both true.
|
||||
`exp1` && `exp2`
|
||||
true if `exp1` and `exp2` are both true.
|
||||
|
||||
- `exp1` `||` `exp2`
|
||||
true if either `exp1` or `exp2` is true.
|
||||
`exp1` \|\| `exp2`
|
||||
true if either `exp1` or `exp2` is true.
|
||||
|
||||
For compatibility, if there is a single argument that is not
|
||||
syntactically significant, typically a variable, the condition is
|
||||
treated as a test for whether the expression expands as a string of
|
||||
non-zero length. In other words, `[[ $var ]]` is the same as `[[ -n $var
|
||||
]]`. It is recommended that the second, explicit, form be used where
|
||||
possible.
|
||||
non-zero length. In other words, \[\[ $var \]\] is the same as \[\[ -n
|
||||
$var \]\]. It is recommended that the second, explicit, form be used
|
||||
where possible.
|
||||
|
||||
Normal shell expansion is performed on the `file`, `string` and
|
||||
`pattern` arguments, but the result of each expansion is constrained to
|
||||
@ -205,66 +202,65 @@ be a single word, similar to the effect of double quotes.
|
||||
|
||||
Filename generation is not performed on any form of argument to
|
||||
conditions. However, it can be forced in any case where normal shell
|
||||
expansion is valid and when the option `EXTENDED_GLOB` is in effect by
|
||||
using an explicit glob qualifier of the form `(#q)` at the end of the
|
||||
string. A normal glob qualifier expression may appear between the ‘`q`’
|
||||
expansion is valid and when the option EXTENDED_GLOB is in effect by
|
||||
using an explicit glob qualifier of the form (#q) at the end of the
|
||||
string. A normal glob qualifier expression may appear between the ‘q’
|
||||
and the closing parenthesis; if none appears the expression has no
|
||||
effect beyond causing filename generation. The results of filename
|
||||
generation are joined together to form a single word, as with the
|
||||
results of other forms of expansion.
|
||||
|
||||
This special use of filename generation is only available with the `[[`
|
||||
syntax. If the condition occurs within the `[` or `test` builtin
|
||||
commands then globbing occurs instead as part of normal command line
|
||||
expansion before the condition is evaluated. In this case it may
|
||||
generate multiple words which are likely to confuse the syntax of the
|
||||
test command.
|
||||
This special use of filename generation is only available with the \[\[
|
||||
syntax. If the condition occurs within the \[ or test builtin commands
|
||||
then globbing occurs instead as part of normal command line expansion
|
||||
before the condition is evaluated. In this case it may generate multiple
|
||||
words which are likely to confuse the syntax of the test command.
|
||||
|
||||
For example,
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
[[ -n file*(#qN) ]]
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
produces status zero if and only if there is at least one file in the
|
||||
current directory beginning with the string ‘`file`’. The globbing
|
||||
qualifier `N` ensures that the expression is empty if there is no
|
||||
matching file.
|
||||
current directory beginning with the string ‘file’. The globbing
|
||||
qualifier N ensures that the expression is empty if there is no matching
|
||||
file.
|
||||
|
||||
Pattern metacharacters are active for the `pattern` arguments; the
|
||||
patterns are the same as those used for filename generation, see
|
||||
[Filename Generation](Expansion.html#Filename-Generation), but there is
|
||||
no special behaviour of ‘`/`’ nor initial dots, and no glob qualifiers
|
||||
are allowed.
|
||||
no special behaviour of ‘/’ nor initial dots, and no glob qualifiers are
|
||||
allowed.
|
||||
|
||||
In each of the above expressions, if `file` is of the form
|
||||
‘`/dev/fd/``n`’, where `n` is an integer, then the test applied to the
|
||||
‘/dev/fd/`n`’, where `n` is an integer, then the test applied to the
|
||||
open file whose descriptor number is `n`, even if the underlying system
|
||||
does not support the `/dev/fd` directory.
|
||||
does not support the /dev/fd directory.
|
||||
|
||||
In the forms which do numeric comparison, the expressions `exp` undergo
|
||||
arithmetic expansion as if they were enclosed in `$((``...``))`.
|
||||
arithmetic expansion as if they were enclosed in $((`...`)).
|
||||
|
||||
For example, the following:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
[[ ( -f foo || -f bar ) && $report = y* ]] && print File exists.
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
tests if either file `foo` or file `bar` exists, and if so, if the value
|
||||
of the parameter `report` begins with ‘`y`’; if the complete condition
|
||||
is true, the message ‘`File exists.`’ is printed.
|
||||
tests if either file foo or file bar exists, and if so, if the value of
|
||||
the parameter report begins with ‘y’; if the complete condition is true,
|
||||
the message ‘File exists.’ is printed.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,109 +8,106 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Files"></span> <span id="Files-1"></span>
|
||||
<span id="Files"></span> <span id="Files-2"></span>
|
||||
|
||||
# 5 Files
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Startup_002fShutdown-Files"></span>
|
||||
|
||||
## 5.1 Startup/Shutdown Files
|
||||
|
||||
<span id="index-files_002c-startup"></span>
|
||||
<span id="index-startup-files"></span>
|
||||
<span id="index-files_002c-shutdown"></span>
|
||||
<span id="index-shutdown-files"></span>
|
||||
<span id="index-RCS_002c-use-of"></span>
|
||||
<span id="index-GLOBAL_005fRCS_002c-use-of"></span>
|
||||
<span id="index-NO_005fRCS_002c-use-of"></span>
|
||||
<span id="index-NO_005fGLOBAL_005fRCS_002c-use-of"></span>
|
||||
<span id="index-ZDOTDIR_002c-use-of"></span>
|
||||
<span id="index-zshenv"></span>
|
||||
<span id="index-files_002c-startup"></span> <span
|
||||
id="index-startup-files"></span> <span
|
||||
id="index-files_002c-shutdown"></span> <span
|
||||
id="index-shutdown-files"></span> <span
|
||||
id="index-RCS_002c-use-of"></span> <span
|
||||
id="index-GLOBAL_005fRCS_002c-use-of"></span> <span
|
||||
id="index-NO_005fRCS_002c-use-of"></span> <span
|
||||
id="index-NO_005fGLOBAL_005fRCS_002c-use-of"></span> <span
|
||||
id="index-ZDOTDIR_002c-use-of"></span> <span id="index-zshenv"></span>
|
||||
|
||||
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`.
|
||||
<span id="index-LOGIN_002c-use-of"></span>
|
||||
<span id="index-zprofile"></span> If the shell is a login shell,
|
||||
commands are read from `/etc/zprofile` and then `$ZDOTDIR/.zprofile`.
|
||||
<span id="index-zshrc"></span> Then, if the shell is interactive,
|
||||
commands are read from `/etc/zshrc` and then `$ZDOTDIR/.zshrc`.
|
||||
<span id="index-zlogin"></span> Finally, if the shell is a login shell,
|
||||
`/etc/zlogin` and `$ZDOTDIR/.zlogin` are read.
|
||||
Commands are then read from $ZDOTDIR/.zshenv. <span
|
||||
id="index-LOGIN_002c-use-of"></span> <span id="index-zprofile"></span>
|
||||
If the shell is a login shell, commands are read from /etc/zprofile and
|
||||
then $ZDOTDIR/.zprofile. <span id="index-zshrc"></span> Then, if the
|
||||
shell is interactive, commands are read from /etc/zshrc and then
|
||||
$ZDOTDIR/.zshrc. <span id="index-zlogin"></span> Finally, if the shell
|
||||
is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
|
||||
|
||||
<span id="index-zlogout"></span>
|
||||
|
||||
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.
|
||||
|
||||
<span id="index-HOME_002c-use-of"></span>
|
||||
|
||||
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.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Files-2"></span>
|
||||
<span id="Files-1"></span>
|
||||
|
||||
## 5.2 Files
|
||||
|
||||
<span id="index-files-used"></span>
|
||||
|
||||
`$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.
|
||||
|
@ -11,55 +11,55 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Functions"></span> <span id="Functions-3"></span>
|
||||
<span id="Functions"></span> <span id="Functions-4"></span>
|
||||
|
||||
# 9 Functions
|
||||
|
||||
<span id="index-functions"></span>
|
||||
<span id="index-function_002c-use-of"></span>
|
||||
<span id="index-functions"></span> <span
|
||||
id="index-function_002c-use-of"></span>
|
||||
|
||||
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.
|
||||
|
||||
<span id="index-return_002c-use-of"></span>
|
||||
|
||||
The `return` builtin is used to return from function calls.
|
||||
The return builtin is used to return from function calls.
|
||||
|
||||
<span id="index-functions_002c-use-of"></span>
|
||||
|
||||
Function identifiers can be listed with the `functions` builtin.
|
||||
<span id="index-unfunction_002c-use-of"></span> Functions can be
|
||||
undefined with the `unfunction` builtin.
|
||||
Function identifiers can be listed with the functions builtin. <span
|
||||
id="index-unfunction_002c-use-of"></span> Functions can be undefined
|
||||
with the unfunction builtin.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Autoloading-Functions"></span>
|
||||
|
||||
## 9.1 Autoloading Functions
|
||||
|
||||
<span id="index-autoloading-functions"></span>
|
||||
<span id="index-functions_002c-autoloading"></span>
|
||||
<span id="index-autoload_002c-use-of"></span>
|
||||
<span id="index-fpath_002c-use-of"></span>
|
||||
<span id="index-autoloading-functions"></span> <span
|
||||
id="index-functions_002c-autoloading"></span> <span
|
||||
id="index-autoload_002c-use-of"></span> <span
|
||||
id="index-fpath_002c-use-of"></span>
|
||||
|
||||
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:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
fpath=(~/myfuncs $fpath)
|
||||
autoload myfunc1 myfunc2 ...
|
||||
```
|
||||
@ -67,62 +67,60 @@ autoload myfunc1 myfunc2 ...
|
||||
</div>
|
||||
|
||||
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.
|
||||
<span id="index-zcompile_002c-use-of"></span> 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.
|
||||
`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.
|
||||
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``.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`.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`.
|
||||
`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.
|
||||
|
||||
<span id="index-KSH_005fAUTOLOAD_002c-use-of"></span>
|
||||
|
||||
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
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
func() { print This is func; }
|
||||
print func is initialized
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
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:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
myfunc() {
|
||||
autoload -X
|
||||
}
|
||||
@ -168,7 +166,7 @@ and
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
unfunction myfunc # if myfunc was defined
|
||||
autoload myfunc
|
||||
myfunc args...
|
||||
@ -176,53 +174,52 @@ myfunc args...
|
||||
|
||||
</div>
|
||||
|
||||
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
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
eval "$(functions)"
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
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:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
autoload +X myfunc
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Anonymous-Functions"></span>
|
||||
|
||||
## 9.2 Anonymous Functions
|
||||
|
||||
<span id="index-anonymous-functions"></span>
|
||||
<span id="index-functions_002c-anonymous"></span>
|
||||
<span id="index-anonymous-functions"></span> <span
|
||||
id="index-functions_002c-anonymous"></span>
|
||||
|
||||
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,
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
variable=outside
|
||||
function {
|
||||
local variable=inside
|
||||
@ -255,7 +252,7 @@ outputs the following:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
I am inside with arguments this and that
|
||||
I am outside
|
||||
```
|
||||
@ -263,11 +260,11 @@ I am outside
|
||||
</div>
|
||||
|
||||
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.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Special-Functions"></span>
|
||||
|
||||
@ -275,63 +272,63 @@ definitions where the definition is silently discarded.
|
||||
|
||||
Certain functions, if defined, have special meaning to the shell.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Hook-Functions"></span>
|
||||
|
||||
### 9.3.1 Hook Functions
|
||||
|
||||
<span id="index-functions_002c-hook"></span>
|
||||
<span id="index-hook-functions"></span>
|
||||
<span id="index-functions_002c-hook"></span> <span
|
||||
id="index-hook-functions"></span>
|
||||
|
||||
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).
|
||||
|
||||
<span id="index-chpwd"></span>
|
||||
<span id="index-chpwd_005ffunctions"></span>
|
||||
<span id="index-chpwd"></span> <span
|
||||
id="index-chpwd_005ffunctions"></span>
|
||||
|
||||
`chpwd`
|
||||
chpwd
|
||||
|
||||
Executed whenever the current working directory is changed.
|
||||
|
||||
<span id="index-periodic"></span>
|
||||
<span id="index-periodic_005ffunctions"></span>
|
||||
<span id="index-periodic"></span> <span
|
||||
id="index-periodic_005ffunctions"></span>
|
||||
|
||||
`periodic`
|
||||
periodic
|
||||
|
||||
<span id="index-PERIOD"></span>
|
||||
|
||||
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.
|
||||
|
||||
<span id="index-precmd"></span>
|
||||
<span id="index-precmd_005ffunctions"></span>
|
||||
<span id="index-precmd"></span> <span
|
||||
id="index-precmd_005ffunctions"></span>
|
||||
|
||||
`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.
|
||||
|
||||
<span id="index-preexec"></span>
|
||||
<span id="index-preexec_005ffunctions"></span>
|
||||
<span id="index-preexec"></span> <span
|
||||
id="index-preexec_005ffunctions"></span>
|
||||
|
||||
`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.
|
||||
|
||||
<span id="index-zshaddhistory"></span>
|
||||
<span id="index-zshaddhistory_005ffunctions"></span>
|
||||
<span id="index-zshaddhistory"></span> <span
|
||||
id="index-zshaddhistory_005ffunctions"></span>
|
||||
|
||||
`zshaddhistory`
|
||||
zshaddhistory
|
||||
|
||||
<span id="index-history_002c-hook-when-line-is-saved"></span>
|
||||
|
||||
@ -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.
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
zshaddhistory() {
|
||||
print -sr -- ${1%%$'\n'}
|
||||
fc -p .zsh_local_history
|
||||
@ -389,17 +386,17 @@ zshaddhistory() {
|
||||
|
||||
</div>
|
||||
|
||||
<span id="index-zshexit"></span>
|
||||
<span id="index-zshexit_005ffunctions"></span>
|
||||
<span id="index-zshexit"></span> <span
|
||||
id="index-zshexit_005ffunctions"></span>
|
||||
|
||||
`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.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Trap-Functions"></span>
|
||||
|
||||
@ -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`
|
||||
<span id="index-signals_002c-trapping"></span>
|
||||
<span id="index-trapping-signals"></span>
|
||||
TRAP`NAL`
|
||||
<span id="index-signals_002c-trapping"></span> <span
|
||||
id="index-trapping-signals"></span>
|
||||
|
||||
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 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`.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
|
||||
<div class="example">
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
TRAPINT() {
|
||||
print "Caught SIGINT, aborting."
|
||||
return $(( 128 + $1 ))
|
||||
}
|
||||
```
|
||||
```zsh
|
||||
TRAPINT() {
|
||||
print "Caught SIGINT, aborting."
|
||||
return $(( 128 + $1 ))
|
||||
}
|
||||
```
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
The functions `TRAPZERR`, `TRAPDEBUG` and `TRAPEXIT` are never
|
||||
executed inside other traps.
|
||||
The functions TRAPZERR, TRAPDEBUG and TRAPEXIT are never executed inside
|
||||
other traps.
|
||||
|
||||
<span id="index-TRAPDEBUG"></span>
|
||||
<span id="index-TRAPDEBUG"></span>
|
||||
|
||||
- `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.
|
||||
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.
|
||||
|
||||
<span id="index-TRAPEXIT"></span>
|
||||
<span id="index-TRAPEXIT"></span>
|
||||
|
||||
- `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.
|
||||
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.
|
||||
|
||||
<span id="index-TRAPZERR"></span> <span id="index-TRAPERR"></span>
|
||||
<span id="index-TRAPZERR"></span> <span id="index-TRAPERR"></span>
|
||||
|
||||
- `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).
|
||||
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).
|
||||
|
||||
<span id="index-trap_002c-use-of"></span>
|
||||
|
||||
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
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
TRAPNAL() {
|
||||
# code
|
||||
}
|
||||
@ -493,7 +488,7 @@ TRAPNAL() {
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` 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.
|
||||
|
@ -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.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Author"></span> <span id="Author-1"></span>
|
||||
|
||||
@ -38,14 +38,13 @@ mechanism, and a host of other features.
|
||||
|
||||
<span id="index-author"></span>
|
||||
|
||||
Zsh was originally written by Paul Falstad `<pf@zsh.org>`. Zsh is now
|
||||
maintained by the members of the zsh-workers mailing list
|
||||
`<zsh-workers@zsh.org>`. The development is currently coordinated by
|
||||
Peter Stephenson `<pws@zsh.org>`. The coordinator can be contacted at
|
||||
`<coordinator@zsh.org>`, 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 \<zsh-workers@zsh.org>. The
|
||||
development is currently coordinated by Peter Stephenson \<pws@zsh.org>.
|
||||
The coordinator can be contacted at \<coordinator@zsh.org>, but matters
|
||||
relating to the code should generally go to the mailing list.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Availability"></span> <span id="Availability-1"></span>
|
||||
|
||||
@ -53,19 +52,19 @@ generally go to the mailing list.
|
||||
|
||||
Zsh is available from the following HTTP and anonymous FTP site.
|
||||
|
||||
<span id="index-FTP-sites-for-zsh"></span>
|
||||
<span id="index-acquiring-zsh-by-FTP"></span>
|
||||
<span id="index-availability-of-zsh"></span>
|
||||
<span id="index-FTP-sites-for-zsh"></span> <span
|
||||
id="index-acquiring-zsh-by-FTP"></span> <span
|
||||
id="index-availability-of-zsh"></span>
|
||||
|
||||
`ftp://ftp.zsh.org/pub/`
|
||||
`https://www.zsh.org/pub/` )
|
||||
<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
|
||||
<https://sourceforge.net/projects/zsh/> for details. A summary of
|
||||
instructions for the archive can be found at
|
||||
`http://zsh.sourceforge.net/`.
|
||||
<https://zsh.sourceforge.io/>.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Mailing-Lists"></span> <span id="Mailing-Lists-1"></span>
|
||||
|
||||
@ -73,32 +72,39 @@ instructions for the archive can be found at
|
||||
|
||||
<span id="index-mailing-lists"></span>
|
||||
|
||||
Zsh has 3 mailing lists:
|
||||
Zsh has several mailing lists:
|
||||
|
||||
- `<zsh-announce@zsh.org>`
|
||||
Announcements about releases, major changes in the shell and the
|
||||
monthly posting of the Zsh FAQ. (moderated)
|
||||
\<zsh-announce@zsh.org>
|
||||
Announcements about releases, major changes in the shell and the monthly
|
||||
posting of the Zsh FAQ. (moderated)
|
||||
|
||||
- `<zsh-users@zsh.org>`
|
||||
User discussions.
|
||||
\<zsh-users@zsh.org>
|
||||
User discussions.
|
||||
|
||||
- `<zsh-workers@zsh.org>`
|
||||
Hacking, development, bug reports and patches.
|
||||
\<zsh-workers@zsh.org>
|
||||
Hacking, development, bug reports and patches.
|
||||
|
||||
\<zsh-security@zsh.org>
|
||||
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.
|
||||
|
||||
`<zsh-announce-subscribe@zsh.org>`
|
||||
\<zsh-announce-subscribe@zsh.org>
|
||||
|
||||
`<zsh-users-subscribe@zsh.org>`
|
||||
\<zsh-users-subscribe@zsh.org>
|
||||
|
||||
`<zsh-workers-subscribe@zsh.org>`
|
||||
\<zsh-workers-subscribe@zsh.org>
|
||||
|
||||
`<zsh-announce-unsubscribe@zsh.org>`
|
||||
\<zsh-announce-unsubscribe@zsh.org>
|
||||
|
||||
`<zsh-users-unsubscribe@zsh.org>`
|
||||
\<zsh-users-unsubscribe@zsh.org>
|
||||
|
||||
`<zsh-workers-unsubscribe@zsh.org>`
|
||||
\<zsh-workers-unsubscribe@zsh.org>
|
||||
|
||||
|
||||
|
||||
@ -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 `<listmaster@zsh.org>`. The mailing lists are
|
||||
maintained by Karsten Thygesen `<karthy@kom.auc.dk>`.
|
||||
lists, send mail to \<listmaster@zsh.org>.
|
||||
|
||||
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 `<gcw@zsh.org>`, available at
|
||||
`https://www.zsh.org/mla/`.
|
||||
administrative addresses listed above. There is also a hypertext archive
|
||||
available at <https://www.zsh.org/mla/>.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="The-Zsh-FAQ"></span> <span id="The-Zsh-FAQ-1"></span>
|
||||
|
||||
## 2.4 The Zsh FAQ
|
||||
|
||||
Zsh has a list of Frequently Asked Questions (FAQ), maintained by Peter
|
||||
Stephenson `<pws@zsh.org>`. It is regularly posted to the newsgroup
|
||||
Stephenson \<pws@zsh.org>. 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 `<faqmaster@zsh.org>`.
|
||||
<https://www.zsh.org/FAQ/>. The contact address for FAQ-related matters
|
||||
is \<faqmaster@zsh.org>.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="The-Zsh-Web-Page"></span>
|
||||
<span id="The-Zsh-Web-Page-1"></span>
|
||||
<span id="The-Zsh-Web-Page"></span> <span
|
||||
id="The-Zsh-Web-Page-1"></span>
|
||||
|
||||
## 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 `<karthy@zsh.org>`, of SunSITE Denmark.
|
||||
The contact address for web-related matters is `<webmaster@zsh.org>`.
|
||||
Zsh has a web page which is located at <https://www.zsh.org/>. The
|
||||
contact address for web-related matters is \<webmaster@zsh.org>.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="The-Zsh-Userguide"></span>
|
||||
<span id="The-Zsh-Userguide-1"></span>
|
||||
<span id="The-Zsh-Userguide"></span> <span
|
||||
id="The-Zsh-Userguide-1"></span>
|
||||
|
||||
## 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 <https://zsh.sourceforge.io/Guide/>. At the time of writing,
|
||||
chapters dealing with startup files and their contents and the new
|
||||
completion system were essentially complete.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="See-Also"></span> <span id="See-Also-1"></span>
|
||||
|
||||
## 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.
|
||||
|
@ -9,213 +9,212 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Invocation"></span> <span id="Invocation-1"></span>
|
||||
<span id="Invocation"></span> <span id="Invocation-2"></span>
|
||||
|
||||
# 4 Invocation
|
||||
|
||||
<span id="index-invocation"></span>
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Invocation-2"></span>
|
||||
<span id="Invocation-1"></span>
|
||||
|
||||
## 4.1 Invocation
|
||||
|
||||
<span id="index-shell-options"></span>
|
||||
<span id="index-options_002c-shell"></span>
|
||||
<span id="index-shell-flags"></span>
|
||||
<span id="index-flags_002c-shell"></span>
|
||||
<span id="index-shell-options"></span> <span
|
||||
id="index-options_002c-shell"></span> <span
|
||||
id="index-shell-flags"></span> <span id="index-flags_002c-shell"></span>
|
||||
|
||||
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,
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
zsh -x -o shwordsplit scr
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
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’.
|
||||
|
||||
<span id="index-long-option"></span>
|
||||
|
||||
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’.
|
||||
|
||||
<span id="index-_002d_002dversion"></span>
|
||||
<span id="index-_002d_002dhelp"></span>
|
||||
<span id="index-_002d_002dversion"></span> <span
|
||||
id="index-_002d_002dhelp"></span>
|
||||
|
||||
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.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Compatibility"></span> <span id="Compatibility-1"></span>
|
||||
|
||||
## 4.2 Compatibility
|
||||
|
||||
<span id="index-compatibility"></span>
|
||||
<span id="index-sh-compatibility"></span>
|
||||
<span id="index-ksh-compatibility"></span>
|
||||
<span id="index-compatibility"></span> <span
|
||||
id="index-sh-compatibility"></span> <span
|
||||
id="index-ksh-compatibility"></span>
|
||||
|
||||
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.
|
||||
|
||||
<span id="index-ENV_002c-use-of"></span>
|
||||
|
||||
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, <https://www.zsh.org/FAQ/>.
|
||||
|
||||
<span id="Restricted-Shell"></span>
|
||||
<span id="Restricted-Shell-1"></span>
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Restricted-Shell"></span> <span
|
||||
id="Restricted-Shell-1"></span>
|
||||
|
||||
## 4.3 Restricted Shell
|
||||
|
||||
<span id="index-restricted-shell"></span>
|
||||
<span id="index-RESTRICTED"></span>
|
||||
<span id="index-restricted-shell"></span> <span
|
||||
id="index-RESTRICTED"></span>
|
||||
|
||||
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.
|
||||
|
@ -8,28 +8,28 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Jobs-_0026-Signals"></span>
|
||||
<span id="Jobs-_0026-Signals-1"></span>
|
||||
<span id="Jobs-_0026-Signals"></span> <span
|
||||
id="Jobs-_0026-Signals-1"></span>
|
||||
|
||||
# 10 Jobs & Signals
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Jobs"></span>
|
||||
|
||||
## 10.1 Jobs
|
||||
|
||||
<span id="index-jobs"></span>
|
||||
<span id="index-MONITOR_002c-use-of"></span>
|
||||
<span id="index-jobs"></span> <span
|
||||
id="index-MONITOR_002c-use-of"></span>
|
||||
|
||||
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:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` 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. <span id="index-jobs_002c-suspending"></span>
|
||||
<span id="index-suspending-jobs"></span> 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,
|
||||
<span id="index-bg_002c-use-of"></span> 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
|
||||
<span id="index-fg_002c-use-of"></span> 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.
|
||||
<span id="index-jobs_002c-suspending"></span> <span
|
||||
id="index-suspending-jobs"></span> 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, <span
|
||||
id="index-bg_002c-use-of"></span> 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 <span id="index-fg_002c-use-of"></span>
|
||||
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. <span id="index-background-jobs_002c-I_002fO"></span>
|
||||
<span id="index-jobs_002c-background_002c-I_002fO"></span> 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. <span id="index-background-jobs_002c-I_002fO"></span> <span
|
||||
id="index-jobs_002c-background_002c-I_002fO"></span> 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.
|
||||
|
||||
<span id="index-jobs_002c-referring-to"></span>
|
||||
<span id="index-referring-to-jobs"></span>
|
||||
<span id="index-jobs_002c-referring-to"></span> <span
|
||||
id="index-referring-to-jobs"></span>
|
||||
|
||||
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.
|
||||
<span id="index-NOTIFY_002c-use-of"></span> 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. <span
|
||||
id="index-NOTIFY_002c-use-of"></span> 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.
|
||||
<span id="index-HUP_002c-use-of"></span>
|
||||
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. <span
|
||||
id="index-HUP_002c-use-of"></span>
|
||||
|
||||
<span id="index-jobs_002c-disowning"></span>
|
||||
<span id="index-disowning-jobs"></span>
|
||||
<span id="index-disown_002c-use-of"></span>
|
||||
<span id="index-jobs_002c-disowning"></span> <span
|
||||
id="index-disowning-jobs"></span> <span
|
||||
id="index-disown_002c-use-of"></span>
|
||||
|
||||
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.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Signals"></span>
|
||||
|
||||
## 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)).
|
||||
|
||||
<span id="index-exiting-shell_002c-and-asynchronous-jobs"></span>
|
||||
<span id="index-asynchronous-jobs_002c-and-exiting-shell"></span>
|
||||
<span id="index-jobs_002c-asynchronous_002c-and-exiting-shell"></span>
|
||||
<span id="index-exiting-shell_002c-and-asynchronous-jobs"></span> <span
|
||||
id="index-asynchronous-jobs_002c-and-exiting-shell"></span> <span
|
||||
id="index-jobs_002c-asynchronous_002c-and-exiting-shell"></span>
|
||||
|
||||
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.
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -11,459 +11,442 @@
|
||||
- [13.2.4 Date and time](#1324-date-and-time)
|
||||
- [13.2.5 Visual effects](#1325-visual-effects)
|
||||
- [13.3 Conditional Substrings in Prompts](#133-conditional-substrings-in-prompts)
|
||||
- [](#)
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="Prompt-Expansion"></span>
|
||||
<span id="Prompt-Expansion-1"></span>
|
||||
<span id="Prompt-Expansion"></span> <span
|
||||
id="Prompt-Expansion-1"></span>
|
||||
|
||||
# 13 Prompt Expansion
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Expansion-of-Prompt-Sequences"></span>
|
||||
|
||||
## 13.1 Expansion of Prompt Sequences
|
||||
|
||||
<span id="index-prompt-expansion"></span>
|
||||
<span id="index-expansion_002c-prompt"></span>
|
||||
<span id="index-prompt-expansion"></span> <span
|
||||
id="index-expansion_002c-prompt"></span>
|
||||
|
||||
Prompt sequences undergo a special form of expansion. This type of
|
||||
expansion is also available using the `-P` option to the `print`
|
||||
builtin.
|
||||
expansion is also available using the -P option to the print builtin.
|
||||
|
||||
<span id="index-PROMPT_005fSUBST_002c-use-of"></span>
|
||||
|
||||
If the `PROMPT_SUBST` option is set, the prompt string is first
|
||||
subjected to *parameter expansion*, *command substitution* and
|
||||
*arithmetic expansion*. See [Expansion](Expansion.html#Expansion).
|
||||
If the PROMPT_SUBST option is set, the prompt string is first subjected
|
||||
to *parameter expansion*, *command substitution* and *arithmetic
|
||||
expansion*. See [Expansion](Expansion.html#Expansion).
|
||||
|
||||
Certain escape sequences may be recognised in the prompt string.
|
||||
|
||||
<span id="index-PROMPT_005fBANG_002c-use-of"></span>
|
||||
|
||||
If the `PROMPT_BANG` option is set, a ‘`!`’ in the prompt is replaced by
|
||||
the current history event number. A literal ‘`!`’ may then be
|
||||
represented as ‘`!!`’.
|
||||
If the PROMPT_BANG option is set, a ‘!’ in the prompt is replaced by the
|
||||
current history event number. A literal ‘!’ may then be represented as
|
||||
‘!!’.
|
||||
|
||||
<span id="index-PROMPT_005fPERCENT_002c-use-of"></span>
|
||||
|
||||
If the `PROMPT_PERCENT` option is set, certain escape sequences that
|
||||
start with ‘`%`’ are expanded. Many escapes are followed by a single
|
||||
character, although some of these take an optional integer argument that
|
||||
should appear between the ‘`%`’ and the next character of the sequence.
|
||||
More complicated escape sequences are available to provide conditional
|
||||
If the PROMPT_PERCENT option is set, certain escape sequences that start
|
||||
with ‘%’ are expanded. Many escapes are followed by a single character,
|
||||
although some of these take an optional integer argument that should
|
||||
appear between the ‘%’ and the next character of the sequence. More
|
||||
complicated escape sequences are available to provide conditional
|
||||
expansion.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Simple-Prompt-Escapes"></span>
|
||||
|
||||
## 13.2 Simple Prompt Escapes
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Special-characters"></span>
|
||||
|
||||
### 13.2.1 Special characters
|
||||
|
||||
- `%%`
|
||||
A ‘`%`’.
|
||||
%%
|
||||
A ‘%’.
|
||||
|
||||
- `%)`
|
||||
A ‘`)`’.
|
||||
%)
|
||||
A ‘)’.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Login-information"></span>
|
||||
|
||||
### 13.2.2 Login information
|
||||
|
||||
- `%l`
|
||||
The line (tty) the user is logged in on, without ‘`/dev/`’ prefix.
|
||||
If the name starts with ‘`/dev/tty`’, that prefix is stripped.
|
||||
%l
|
||||
The line (tty) the user is logged in on, without ‘/dev/’ prefix. If the
|
||||
name starts with ‘/dev/tty’, that prefix is stripped.
|
||||
|
||||
- `%M`
|
||||
The full machine hostname.
|
||||
%M
|
||||
The full machine hostname.
|
||||
|
||||
- `%m`
|
||||
The hostname up to the first ‘`.`’. An integer may follow the ‘`%`’
|
||||
to specify how many components of the hostname are desired. With a
|
||||
negative integer, trailing components of the hostname are shown.
|
||||
%m
|
||||
The hostname up to the first ‘.’. An integer may follow the ‘%’ to
|
||||
specify how many components of the hostname are desired. With a negative
|
||||
integer, trailing components of the hostname are shown.
|
||||
|
||||
- `%n`
|
||||
`$USERNAME`.
|
||||
%n
|
||||
$USERNAME.
|
||||
|
||||
- `%y`
|
||||
The line (tty) the user is logged in on, without ‘`/dev/`’ prefix.
|
||||
This does not treat ‘`/dev/tty`’ names specially.
|
||||
%y
|
||||
The line (tty) the user is logged in on, without ‘/dev/’ prefix. This
|
||||
does not treat ‘/dev/tty’ names specially.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Shell-state"></span>
|
||||
|
||||
### 13.2.3 Shell state
|
||||
|
||||
- `%#`
|
||||
A ‘`#`’ if the shell is running with privileges, a ‘`%`’ if not.
|
||||
Equivalent to ‘`%(!.#.%%)`’. The definition of ‘privileged’, for
|
||||
these purposes, is that either the effective user ID is zero, or, if
|
||||
POSIX.1e capabilities are supported, that capability vectors.
|
||||
%#
|
||||
A ‘#’ if the shell is running with privileges, a ‘%’ if not. Equivalent
|
||||
to ‘%(!.#.%%)’. The definition of ‘privileged’, for these purposes, is
|
||||
that either the effective user ID is zero, or, if POSIX.1e capabilities
|
||||
are supported, that capability vectors.
|
||||
|
||||
- `%?`
|
||||
The return status of the last command executed just before the
|
||||
prompt.
|
||||
%?
|
||||
The return status of the last command executed just before the prompt.
|
||||
|
||||
- `%_`
|
||||
The status of the parser, i.e. the shell constructs (like ‘`if`’ and
|
||||
‘`for`’) that have been started on the command line. If given an
|
||||
integer number that many strings will be printed; zero or negative
|
||||
or no integer means print as many as there are. This is most useful
|
||||
in prompts `PS2` for continuation lines and `PS4` for debugging with
|
||||
the `XTRACE` option; in the latter case it will also work
|
||||
non-interactively.
|
||||
%\_
|
||||
The status of the parser, i.e. the shell constructs (like ‘if’ and
|
||||
‘for’) that have been started on the command line. If given an integer
|
||||
number that many strings will be printed; zero or negative or no integer
|
||||
means print as many as there are. This is most useful in prompts PS2 for
|
||||
continuation lines and PS4 for debugging with the XTRACE option; in the
|
||||
latter case it will also work non-interactively.
|
||||
|
||||
- `%^`
|
||||
The status of the parser in reverse. This is the same as ‘`%_`’
|
||||
other than the order of strings. It is often used in `RPS2`.
|
||||
%^
|
||||
The status of the parser in reverse. This is the same as ‘%\_’ other
|
||||
than the order of strings. It is often used in RPS2.
|
||||
|
||||
- `%d`
|
||||
`%/`
|
||||
Current working directory. If an integer follows the ‘`%`’, it
|
||||
specifies a number of trailing components of the current working
|
||||
directory to show; zero means the whole path. A negative integer
|
||||
specifies leading components, i.e. `%-1d` specifies the first
|
||||
component.
|
||||
%d
|
||||
%/
|
||||
Current working directory. If an integer follows the ‘%’, it specifies a
|
||||
number of trailing components of the current working directory to show;
|
||||
zero means the whole path. A negative integer specifies leading
|
||||
components, i.e. %-1d specifies the first component.
|
||||
|
||||
- `%~`
|
||||
As `%d` and `%/`, but if the current working directory starts with
|
||||
`$HOME`, that part is replaced by a ‘`~`’. Furthermore, if it has a
|
||||
named directory as its prefix, that part is replaced by a ‘`~`’
|
||||
followed by the name of the directory, but only if the result is
|
||||
shorter than the full path; [Filename
|
||||
Expansion](Expansion.html#Filename-Expansion).
|
||||
%\~
|
||||
As %d and %/, but if the current working directory starts with $HOME,
|
||||
that part is replaced by a ‘\~’. Furthermore, if it has a named
|
||||
directory as its prefix, that part is replaced by a ‘\~’ followed by the
|
||||
name of the directory, but only if the result is shorter than the full
|
||||
path; [Filename Expansion](Expansion.html#Filename-Expansion).
|
||||
|
||||
- `%e`
|
||||
Evaluation depth of the current sourced file, shell function, or
|
||||
`eval`. This is incremented or decremented every time the value of
|
||||
`%N` is set or reverted to a previous value, respectively. This is
|
||||
most useful for debugging as part of `$PS4`.
|
||||
%e
|
||||
Evaluation depth of the current sourced file, shell function, or eval.
|
||||
This is incremented or decremented every time the value of %N is set or
|
||||
reverted to a previous value, respectively. This is most useful for
|
||||
debugging as part of $PS4.
|
||||
|
||||
- `%h`
|
||||
`%!`
|
||||
Current history event number.
|
||||
%h
|
||||
%!
|
||||
Current history event number.
|
||||
|
||||
- `%i`
|
||||
The line number currently being executed in the script, sourced
|
||||
file, or shell function given by `%N`. This is most useful for
|
||||
debugging as part of `$PS4`.
|
||||
%i
|
||||
The line number currently being executed in the script, sourced file, or
|
||||
shell function given by %N. This is most useful for debugging as part of
|
||||
$PS4.
|
||||
|
||||
- `%I`
|
||||
The line number currently being executed in the file `%x`. This is
|
||||
similar to `%i`, but the line number is always a line number in the
|
||||
file where the code was defined, even if the code is a shell
|
||||
function.
|
||||
%I
|
||||
The line number currently being executed in the file %x. This is similar
|
||||
to %i, but the line number is always a line number in the file where the
|
||||
code was defined, even if the code is a shell function.
|
||||
|
||||
- `%j`
|
||||
The number of jobs.
|
||||
%j
|
||||
The number of jobs.
|
||||
|
||||
- `%L`
|
||||
The current value of `$SHLVL`.
|
||||
%L
|
||||
The current value of $SHLVL.
|
||||
|
||||
- `%N`
|
||||
The name of the script, sourced file, or shell function that zsh is
|
||||
currently executing, whichever was started most recently. If there
|
||||
is none, this is equivalent to the parameter `$0`. An integer may
|
||||
follow the ‘`%`’ to specify a number of trailing path components to
|
||||
show; zero means the full path. A negative integer specifies leading
|
||||
components.
|
||||
%N
|
||||
The name of the script, sourced file, or shell function that zsh is
|
||||
currently executing, whichever was started most recently. If there is
|
||||
none, this is equivalent to the parameter $0. An integer may follow the
|
||||
‘%’ to specify a number of trailing path components to show; zero means
|
||||
the full path. A negative integer specifies leading components.
|
||||
|
||||
- `%x`
|
||||
The name of the file containing the source code currently being
|
||||
executed. This behaves as `%N` except that function and eval command
|
||||
names are not shown, instead the file where they were defined.
|
||||
%x
|
||||
The name of the file containing the source code currently being
|
||||
executed. This behaves as %N except that function and eval command names
|
||||
are not shown, instead the file where they were defined.
|
||||
|
||||
- `%c`
|
||||
`%.`
|
||||
`%C`
|
||||
Trailing component of the current working directory. An integer may
|
||||
follow the ‘`%`’ to get more than one component. Unless ‘`%C`’ is
|
||||
used, tilde contraction is performed first. These are deprecated as
|
||||
`%c` and `%C` are equivalent to `%1~` and `%1/`, respectively, while
|
||||
explicit positive integers have the same effect as for the latter
|
||||
two sequences.
|
||||
%c
|
||||
%.
|
||||
%C
|
||||
Trailing component of the current working directory. An integer may
|
||||
follow the ‘%’ to get more than one component. Unless ‘%C’ is used,
|
||||
tilde contraction is performed first. These are deprecated as %c and %C
|
||||
are equivalent to %1\~ and %1/, respectively, while explicit positive
|
||||
integers have the same effect as for the latter two sequences.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Date-and-time"></span>
|
||||
|
||||
### 13.2.4 Date and time
|
||||
|
||||
- `%D`
|
||||
The date in `yy``-``mm``-``dd` format.
|
||||
%D
|
||||
The date in `yy`-`mm`-`dd` format.
|
||||
|
||||
- `%T`
|
||||
Current time of day, in 24-hour format.
|
||||
%T
|
||||
Current time of day, in 24-hour format.
|
||||
|
||||
- `%t`
|
||||
`%@`
|
||||
Current time of day, in 12-hour, am/pm format.
|
||||
%t
|
||||
%@
|
||||
Current time of day, in 12-hour, am/pm format.
|
||||
|
||||
- `%*`
|
||||
Current time of day in 24-hour format, with seconds.
|
||||
%\*
|
||||
Current time of day in 24-hour format, with seconds.
|
||||
|
||||
- `%w`
|
||||
The date in `day``-``dd` format.
|
||||
%w
|
||||
The date in `day`-`dd` format.
|
||||
|
||||
- `%W`
|
||||
The date in `mm``/``dd``/``yy` format.
|
||||
%W
|
||||
The date in `mm`/`dd`/`yy` format.
|
||||
|
||||
- `%D{``string``}`
|
||||
`string` is formatted using the `strftime` function. See man page
|
||||
strftime(3) for more details. Various zsh extensions provide numbers
|
||||
with no leading zero or space if the number is a single digit:
|
||||
%D{`string`}
|
||||
`string` is formatted using the strftime function. See strftime(3) for
|
||||
more details. Various zsh extensions provide numbers with no leading
|
||||
zero or space if the number is a single digit:
|
||||
|
||||
- `%f`
|
||||
a day of the month
|
||||
%f
|
||||
a day of the month
|
||||
|
||||
- `%K`
|
||||
the hour of the day on the 24-hour clock
|
||||
%K
|
||||
the hour of the day on the 24-hour clock
|
||||
|
||||
- `%L`
|
||||
the hour of the day on the 12-hour clock
|
||||
%L
|
||||
the hour of the day on the 12-hour clock
|
||||
|
||||
In addition, if the system supports the POSIX `gettimeofday` system
|
||||
call, `%.` provides decimal fractions of a second since the epoch
|
||||
with leading zeroes. By default three decimal places are provided,
|
||||
but a number of digits up to 9 may be given following the `%`; hence
|
||||
`%6.` outputs microseconds, and `%9.` outputs nanoseconds. (The
|
||||
latter requires a nanosecond-precision `clock_gettime`; systems
|
||||
lacking this will return a value multiplied by the appropriate power
|
||||
of 10.) A typical example of this is the format ‘`%D{%H:%M:%S.%.}`’.
|
||||
In addition, if the system supports the POSIX gettimeofday system call,
|
||||
%. provides decimal fractions of a second since the epoch with leading
|
||||
zeroes. By default three decimal places are provided, but a number of
|
||||
digits up to 9 may be given following the %; hence %6. outputs
|
||||
microseconds, and %9. outputs nanoseconds. (The latter requires a
|
||||
nanosecond-precision clock_gettime; systems lacking this will return a
|
||||
value multiplied by the appropriate power of 10.) A typical example of
|
||||
this is the format ‘%D{%H:%M:%S.%.}’.
|
||||
|
||||
The GNU extension `%N` is handled as a synonym for `%9.`.
|
||||
The GNU extension %N is handled as a synonym for %9..
|
||||
|
||||
Additionally, the GNU extension that a ‘`-`’ between the `%` and the
|
||||
format character causes a leading zero or space to be stripped is
|
||||
handled directly by the shell for the format characters `d`, `f`,
|
||||
`H`, `k`, `l`, `m`, `M`, `S` and `y`; any other format characters
|
||||
are provided to the system’s strftime(3) with any leading ‘`-`’
|
||||
present, so the handling is system dependent. Further GNU (or other)
|
||||
extensions are also passed to strftime(3) and may work if the system
|
||||
supports them.
|
||||
Additionally, the GNU extension that a ‘-’ between the % and the format
|
||||
character causes a leading zero or space to be stripped is handled
|
||||
directly by the shell for the format characters d, f, H, k, l, m, M, S
|
||||
and y; any other format characters are provided to the system’s
|
||||
strftime(3) with any leading ‘-’ present, so the handling is system
|
||||
dependent. Further GNU (or other) extensions are also passed to
|
||||
strftime(3) and may work if the system supports them.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Visual-effects"></span>
|
||||
|
||||
### 13.2.5 Visual effects
|
||||
|
||||
- `%B` (`%b`)
|
||||
Start (stop) boldface mode.
|
||||
%B (%b)
|
||||
Start (stop) boldface mode.
|
||||
|
||||
- `%E`
|
||||
Clear to end of line.
|
||||
%E
|
||||
Clear to end of line.
|
||||
|
||||
- `%U` (`%u`)
|
||||
Start (stop) underline mode.
|
||||
%U (%u)
|
||||
Start (stop) underline mode.
|
||||
|
||||
- `%S` (`%s`)
|
||||
Start (stop) standout mode.
|
||||
%S (%s)
|
||||
Start (stop) standout mode.
|
||||
|
||||
- `%F` (`%f`)
|
||||
Start (stop) using a different foreground colour, if supported by
|
||||
the terminal. The colour may be specified two ways: either as a
|
||||
numeric argument, as normal, or by a sequence in braces following
|
||||
the `%F`, for example `%F{red}`. In the latter case the values
|
||||
allowed are as described for the `fg` `zle_highlight` attribute;
|
||||
[Character
|
||||
Highlighting](Zsh-Line-Editor.html#Character-Highlighting). This
|
||||
means that numeric colours are allowed in the second format also.
|
||||
%F (%f)
|
||||
Start (stop) using a different foreground colour, if supported by the
|
||||
terminal. The colour may be specified two ways: either as a numeric
|
||||
argument, as normal, or by a sequence in braces following the %F, for
|
||||
example %F{red}. In the latter case the values allowed are as described
|
||||
for the fg zle_highlight attribute; [Character
|
||||
Highlighting](Zsh-Line-Editor.html#Character-Highlighting). This means
|
||||
that numeric colours are allowed in the second format also.
|
||||
|
||||
- `%K` (`%k`)
|
||||
Start (stop) using a different bacKground colour. The syntax is
|
||||
identical to that for `%F` and `%f`.
|
||||
%K (%k)
|
||||
Start (stop) using a different bacKground colour. The syntax is
|
||||
identical to that for %F and %f.
|
||||
|
||||
- `%{`...`%}`
|
||||
Include a string as a literal escape sequence. The string within the
|
||||
braces should not change the cursor position. Brace pairs can nest.
|
||||
%{...%}
|
||||
Include a string as a literal escape sequence. The string within the
|
||||
braces should not change the cursor position. Brace pairs can nest.
|
||||
|
||||
A positive numeric argument between the `%` and the `{` is treated
|
||||
as described for `%G` below.
|
||||
A positive numeric argument between the % and the { is treated as
|
||||
described for %G below.
|
||||
|
||||
- `%G`
|
||||
Within a `%{`...`%}` sequence, include a ‘glitch’: that is, assume
|
||||
that a single character width will be output. This is useful when
|
||||
outputting characters that otherwise cannot be correctly handled by
|
||||
the shell, such as the alternate character set on some terminals.
|
||||
The characters in question can be included within a `%{`...`%}`
|
||||
sequence together with the appropriate number of `%G` sequences to
|
||||
indicate the correct width. An integer between the ‘`%`’ and ‘`G`’
|
||||
indicates a character width other than one. Hence `%{``seq``%2G%}`
|
||||
outputs `seq` and assumes it takes up the width of two standard
|
||||
characters.
|
||||
%G
|
||||
Within a %{...%} sequence, include a ‘glitch’: that is, assume that a
|
||||
single character width will be output. This is useful when outputting
|
||||
characters that otherwise cannot be correctly handled by the shell, such
|
||||
as the alternate character set on some terminals. The characters in
|
||||
question can be included within a %{...%} sequence together with the
|
||||
appropriate number of %G sequences to indicate the correct width. An
|
||||
integer between the ‘%’ and ‘G’ indicates a character width other than
|
||||
one. Hence %{`seq`%2G%} outputs `seq` and assumes it takes up the width
|
||||
of two standard characters.
|
||||
|
||||
Multiple uses of `%G` accumulate in the obvious fashion; the
|
||||
position of the `%G` is unimportant. Negative integers are not
|
||||
handled.
|
||||
Multiple uses of %G accumulate in the obvious fashion; the position of
|
||||
the %G is unimportant. Negative integers are not handled.
|
||||
|
||||
Note that when prompt truncation is in use it is advisable to divide
|
||||
up output into single characters within each `%{`...`%}` group so
|
||||
that the correct truncation point can be found.
|
||||
Note that when prompt truncation is in use it is advisable to divide up
|
||||
output into single characters within each %{...%} group so that the
|
||||
correct truncation point can be found.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Conditional-Substrings-in-Prompts"></span>
|
||||
|
||||
## 13.3 Conditional Substrings in Prompts
|
||||
|
||||
- `%v`
|
||||
<span id="index-psvar_002c-use-of"></span>
|
||||
%v
|
||||
<span id="index-psvar_002c-use-of"></span>
|
||||
|
||||
The value of the first element of the `psvar` array parameter.
|
||||
Following the ‘`%`’ with an integer gives that element of the array.
|
||||
Negative integers count from the end of the array.
|
||||
The value of the first element of the psvar array parameter. Following
|
||||
the ‘%’ with an integer gives that element of the array. Negative
|
||||
integers count from the end of the array.
|
||||
|
||||
- `%(``x``.``true-text``.``false-text``)`
|
||||
Specifies a ternary expression. The character following the `x` is
|
||||
arbitrary; the same character is used to separate the text for the
|
||||
‘true’ result from that for the ‘false’ result. This separator may
|
||||
not appear in the `true-text`, except as part of a %-escape
|
||||
sequence. A ‘`)`’ may appear in the `false-text` as ‘`%)`’.
|
||||
`true-text` and `false-text` may both contain arbitrarily-nested
|
||||
escape sequences, including further ternary expressions.
|
||||
%(`x`.`true-text`.`false-text`)
|
||||
Specifies a ternary expression. The character following the `x` is
|
||||
arbitrary; the same character is used to separate the text for the
|
||||
‘true’ result from that for the ‘false’ result. This separator may not
|
||||
appear in the `true-text`, except as part of a %-escape sequence. A ‘)’
|
||||
may appear in the `false-text` as ‘%)’. `true-text` and `false-text` may
|
||||
both contain arbitrarily-nested escape sequences, including further
|
||||
ternary expressions.
|
||||
|
||||
The left parenthesis may be preceded or followed by a positive
|
||||
integer `n`, which defaults to zero. A negative integer will be
|
||||
multiplied by -1, except as noted below for ‘`l`’. The test
|
||||
character `x` may be any of the following:
|
||||
The left parenthesis may be preceded or followed by a positive integer
|
||||
`n`, which defaults to zero. A negative integer will be multiplied by
|
||||
-1, except as noted below for ‘l’. The test character `x` may be any of
|
||||
the following:
|
||||
|
||||
- `!`
|
||||
True if the shell is running with privileges.
|
||||
!
|
||||
True if the shell is running with privileges.
|
||||
|
||||
- `#`
|
||||
True if the effective uid of the current process is `n`.
|
||||
#
|
||||
True if the effective uid of the current process is `n`.
|
||||
|
||||
- `?`
|
||||
True if the exit status of the last command was `n`.
|
||||
?
|
||||
True if the exit status of the last command was `n`.
|
||||
|
||||
- `_`
|
||||
True if at least `n` shell constructs were started.
|
||||
\_
|
||||
True if at least `n` shell constructs were started.
|
||||
|
||||
- `C`
|
||||
`/`
|
||||
True if the current absolute path has at least `n` elements
|
||||
relative to the root directory, hence `/` is counted as 0
|
||||
elements.
|
||||
C
|
||||
/
|
||||
True if the current absolute path has at least `n` elements relative to
|
||||
the root directory, hence / is counted as 0 elements.
|
||||
|
||||
- `c`
|
||||
`.`
|
||||
`~`
|
||||
True if the current path, with prefix replacement, has at least
|
||||
`n` elements relative to the root directory, hence `/` is
|
||||
counted as 0 elements.
|
||||
c
|
||||
.
|
||||
\~
|
||||
True if the current path, with prefix replacement, has at least `n`
|
||||
elements relative to the root directory, hence / is counted as 0
|
||||
elements.
|
||||
|
||||
- `D`
|
||||
True if the month is equal to `n` (January = 0).
|
||||
D
|
||||
True if the month is equal to `n` (January = 0).
|
||||
|
||||
- `d`
|
||||
True if the day of the month is equal to `n`.
|
||||
d
|
||||
True if the day of the month is equal to `n`.
|
||||
|
||||
- `e`
|
||||
True if the evaluation depth is at least `n`.
|
||||
e
|
||||
True if the evaluation depth is at least `n`.
|
||||
|
||||
- `g`
|
||||
True if the effective gid of the current process is `n`.
|
||||
g
|
||||
True if the effective gid of the current process is `n`.
|
||||
|
||||
- `j`
|
||||
True if the number of jobs is at least `n`.
|
||||
j
|
||||
True if the number of jobs is at least `n`.
|
||||
|
||||
- `L`
|
||||
True if the `SHLVL` parameter is at least `n`.
|
||||
L
|
||||
True if the SHLVL parameter is at least `n`.
|
||||
|
||||
- `l`
|
||||
True if at least `n` characters have already been printed on the
|
||||
current line. When `n` is negative, true if at least
|
||||
`abs``(``n``)` characters remain before the opposite margin
|
||||
(thus the left margin for `RPROMPT`).
|
||||
l
|
||||
True if at least `n` characters have already been printed on the current
|
||||
line. When `n` is negative, true if at least abs(`n`) characters remain
|
||||
before the opposite margin (thus the left margin for RPROMPT).
|
||||
|
||||
- `S`
|
||||
True if the `SECONDS` parameter is at least `n`.
|
||||
S
|
||||
True if the SECONDS parameter is at least `n`.
|
||||
|
||||
- `T`
|
||||
True if the time in hours is equal to `n`.
|
||||
T
|
||||
True if the time in hours is equal to `n`.
|
||||
|
||||
- `t`
|
||||
True if the time in minutes is equal to `n`.
|
||||
t
|
||||
True if the time in minutes is equal to `n`.
|
||||
|
||||
- `v`
|
||||
True if the array `psvar` has at least `n` elements.
|
||||
v
|
||||
True if the array psvar has at least `n` elements.
|
||||
|
||||
- `V`
|
||||
True if element `n` of the array `psvar` is set and non-empty.
|
||||
V
|
||||
True if element `n` of the array psvar is set and non-empty.
|
||||
|
||||
- `w`
|
||||
True if the day of the week is equal to `n` (Sunday = 0).
|
||||
w
|
||||
True if the day of the week is equal to `n` (Sunday = 0).
|
||||
|
||||
- `%<``string``<`
|
||||
`%>``string``>`
|
||||
`%[``xstring``]`
|
||||
Specifies truncation behaviour for the remainder of the prompt
|
||||
string. The third, deprecated, form is equivalent to
|
||||
‘`%``xstringx`’, i.e. `x` may be ‘`<`’ or ‘`>`’. The `string`
|
||||
will be displayed in place of the truncated portion of any string;
|
||||
note this does not undergo prompt expansion.
|
||||
%\<`string`\<
|
||||
%>`string`\>
|
||||
%\[`xstring`\]
|
||||
Specifies truncation behaviour for the remainder of the prompt string.
|
||||
The third, deprecated, form is equivalent to ‘%`xstringx`’, i.e. `x` may
|
||||
be ‘\<’ or ‘>’. The `string` will be displayed in place of the truncated
|
||||
portion of any string; note this does not undergo prompt expansion.
|
||||
|
||||
The numeric argument, which in the third form may appear immediately
|
||||
after the ‘`[`’, specifies the maximum permitted length of the
|
||||
various strings that can be displayed in the prompt. In the first
|
||||
two forms, this numeric argument may be negative, in which case the
|
||||
truncation length is determined by subtracting the absolute value of
|
||||
the numeric argument from the number of character positions
|
||||
remaining on the current prompt line. If this results in a zero or
|
||||
negative length, a length of 1 is used. In other words, a negative
|
||||
argument arranges that after truncation at least `n` characters
|
||||
remain before the right margin (left margin for `RPROMPT`).
|
||||
The numeric argument, which in the third form may appear immediately
|
||||
after the ‘\[’, specifies the maximum permitted length of the various
|
||||
strings that can be displayed in the prompt. In the first two forms,
|
||||
this numeric argument may be negative, in which case the truncation
|
||||
length is determined by subtracting the absolute value of the numeric
|
||||
argument from the number of character positions remaining on the current
|
||||
prompt line. If this results in a zero or negative length, a length of 1
|
||||
is used. In other words, a negative argument arranges that after
|
||||
truncation at least `n` characters remain before the right margin (left
|
||||
margin for RPROMPT).
|
||||
|
||||
The forms with ‘`<`’ truncate at the left of the string, and the
|
||||
forms with ‘`>`’ truncate at the right of the string. For example,
|
||||
if the current directory is ‘`/home/pike`’, the prompt ‘`%8<..<%/`’
|
||||
will expand to ‘`..e/pike`’. In this string, the terminating
|
||||
character (‘`<`’, ‘`>`’ or ‘`]`’), or in fact any character, may be
|
||||
quoted by a preceding ‘`\`’; note when using `print -P`, however,
|
||||
that this must be doubled as the string is also subject to standard
|
||||
`print` processing, in addition to any backslashes removed by a
|
||||
double quoted string: the worst case is therefore ‘`print -P
|
||||
"%<\\\\<<..."`’.
|
||||
The forms with ‘\<’ truncate at the left of the string, and the forms
|
||||
with ‘>’ truncate at the right of the string. For example, if the
|
||||
current directory is ‘/home/pike’, the prompt ‘%8\<..\<%/’ will expand
|
||||
to ‘..e/pike’. In this string, the terminating character (‘\<’, ‘>’ or
|
||||
‘\]’), or in fact any character, may be quoted by a preceding ‘\\’; note
|
||||
when using print -P, however, that this must be doubled as the string is
|
||||
also subject to standard print processing, in addition to any
|
||||
backslashes removed by a double quoted string: the worst case is
|
||||
therefore ‘print -P "%\<\\\\\\\\\<\<..."’.
|
||||
|
||||
If the `string` is longer than the specified truncation length, it
|
||||
will appear in full, completely replacing the truncated string.
|
||||
If the `string` is longer than the specified truncation length, it will
|
||||
appear in full, completely replacing the truncated string.
|
||||
|
||||
The part of the prompt string to be truncated runs to the end of the
|
||||
string, or to the end of the next enclosing group of the ‘`%(`’
|
||||
construct, or to the next truncation encountered at the same
|
||||
grouping level (i.e. truncations inside a ‘`%(`’ are separate),
|
||||
which ever comes first. In particular, a truncation with argument
|
||||
zero (e.g., ‘`%<<`’) marks the end of the range of the string to be
|
||||
truncated while turning off truncation from there on. For example,
|
||||
the prompt ‘` %10<...<%~%<<%# `’ will print a truncated
|
||||
representation of the current directory, followed by a ‘`%`’ or
|
||||
‘`#`’, followed by a space. Without the ‘`%<<`’, those two
|
||||
characters would be included in the string to be truncated. Note
|
||||
that ‘`%-0<<`’ is not equivalent to ‘`%<<`’ but specifies that the
|
||||
prompt is truncated at the right margin.
|
||||
The part of the prompt string to be truncated runs to the end of the
|
||||
string, or to the end of the next enclosing group of the ‘%(’ construct,
|
||||
or to the next truncation encountered at the same grouping level (i.e.
|
||||
truncations inside a ‘%(’ are separate), which ever comes first. In
|
||||
particular, a truncation with argument zero (e.g., ‘%\<\<’) marks the
|
||||
end of the range of the string to be truncated while turning off
|
||||
truncation from there on. For example, the prompt ‘%10\<...\<%\~%\<\<%#
|
||||
’ will print a truncated representation of the current directory,
|
||||
followed by a ‘%’ or ‘#’, followed by a space. Without the ‘%\<\<’,
|
||||
those two characters would be included in the string to be truncated.
|
||||
Note that ‘%-0\<\<’ is not equivalent to ‘%\<\<’ but specifies that the
|
||||
prompt is truncated at the right margin.
|
||||
|
||||
Truncation applies only within each individual line of the prompt,
|
||||
as delimited by embedded newlines (if any). If the total length of
|
||||
any line of the prompt after truncation is greater than the terminal
|
||||
width, or if the part to be truncated contains embedded newlines,
|
||||
truncation behavior is undefined and may change in a future version
|
||||
of the shell. Use ‘`%-``n``(l.``true-text``.``false-text``)`’ to
|
||||
remove parts of the prompt when the available space is less than
|
||||
`n`.
|
||||
Truncation applies only within each individual line of the prompt, as
|
||||
delimited by embedded newlines (if any). If the total length of any line
|
||||
of the prompt after truncation is greater than the terminal width, or if
|
||||
the part to be truncated contains embedded newlines, truncation behavior
|
||||
is undefined and may change in a future version of the shell. Use
|
||||
‘%-`n`(l.`true-text`.`false-text`)’ to remove parts of the prompt when
|
||||
the available space is less than `n`.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
@ -13,12 +13,12 @@
|
||||
|
||||
# 7 Redirection
|
||||
|
||||
<span id="index-redirection"></span>
|
||||
<span id="index-file-descriptors"></span>
|
||||
<span id="index-descriptors_002c-file"></span>
|
||||
<span id="index-redirection"></span> <span
|
||||
id="index-file-descriptors"></span> <span
|
||||
id="index-descriptors_002c-file"></span>
|
||||
|
||||
If a command is followed by `&` and job control is not active, then the
|
||||
default standard input for the command is the empty file `/dev/null`.
|
||||
If a command is followed by & and job control is not active, then the
|
||||
default standard input for the command is the empty file /dev/null.
|
||||
Otherwise, the environment for the execution of a command contains the
|
||||
file descriptors of the invoking shell as modified by input/output
|
||||
specifications.
|
||||
@ -29,107 +29,103 @@ used except as noted below. If the result of substitution on `word`
|
||||
produces more than one filename, redirection occurs for each separate
|
||||
filename in turn.
|
||||
|
||||
- `<` `word`
|
||||
Open file `word` for reading as standard input. It is an error to
|
||||
open a file in this fashion if it does not exist.
|
||||
\< `word`
|
||||
Open file `word` for reading as standard input. It is an error to open a
|
||||
file in this fashion if it does not exist.
|
||||
|
||||
- `<>` `word`
|
||||
Open file `word` for reading and writing as standard input. If the
|
||||
file does not exist then it is created.
|
||||
\<\> `word`
|
||||
Open file `word` for reading and writing as standard input. If the file
|
||||
does not exist then it is created.
|
||||
|
||||
- `>` `word`
|
||||
Open file `word` for writing as standard output. If the file does
|
||||
not exist then it is created. If the file exists, and the `CLOBBER`
|
||||
option is unset, this causes an error; otherwise, it is truncated to
|
||||
zero length.
|
||||
\> `word`
|
||||
Open file `word` for writing as standard output. If the file does not
|
||||
exist then it is created. If the file exists, and the CLOBBER option is
|
||||
unset, this causes an error; otherwise, it is truncated to zero length.
|
||||
|
||||
- `>|` `word`
|
||||
`>!` `word`
|
||||
Same as `>`, except that the file is truncated to zero length if it
|
||||
exists, regardless of `CLOBBER`.
|
||||
\>\| `word`
|
||||
\>! `word`
|
||||
Same as >, except that the file is truncated to zero length if it
|
||||
exists, regardless of CLOBBER.
|
||||
|
||||
- `>>` `word`
|
||||
Open file `word` for writing in append mode as standard output. If
|
||||
the file does not exist, and the `CLOBBER` and `APPEND_CREATE`
|
||||
options are both unset, this causes an error; otherwise, the file is
|
||||
created.
|
||||
\>\> `word`
|
||||
Open file `word` for writing in append mode as standard output. If the
|
||||
file does not exist, and the CLOBBER and APPEND_CREATE options are both
|
||||
unset, this causes an error; otherwise, the file is created.
|
||||
|
||||
- `>>|` `word`
|
||||
`>>!` `word`
|
||||
Same as `>>`, except that the file is created if it does not exist,
|
||||
regardless of `CLOBBER` and `APPEND_CREATE`.
|
||||
\>\>\| `word`
|
||||
\>\>! `word`
|
||||
Same as >\>, except that the file is created if it does not exist,
|
||||
regardless of CLOBBER and APPEND_CREATE.
|
||||
|
||||
- `<<`\[`-`\] `word`
|
||||
The shell input is read up to a line that is the same as `word`, or
|
||||
to an end-of-file. No parameter expansion, command substitution or
|
||||
filename generation is performed on `word`. The resulting document,
|
||||
called a *here-document*, becomes the standard input.
|
||||
\<\<\[-\] `word`
|
||||
The shell input is read up to a line that is the same as `word`, or to
|
||||
an end-of-file. No parameter expansion, command substitution or filename
|
||||
generation is performed on `word`. The resulting document, called a
|
||||
*here-document*, becomes the standard input.
|
||||
|
||||
If any character of `word` is quoted with single or double quotes or
|
||||
a ‘`\`’, no interpretation is placed upon the characters of the
|
||||
document. Otherwise, parameter and command substitution occurs,
|
||||
‘`\`’ followed by a newline is removed, and ‘`\`’ must be used
|
||||
to quote the characters ‘`\`’, ‘`$`’, ‘`‘`’ and the first character
|
||||
of `word`.
|
||||
If any character of `word` is quoted with single or double quotes or a
|
||||
‘\\’, no interpretation is placed upon the characters of the document.
|
||||
Otherwise, parameter and command substitution occurs, ‘\\’ followed by a
|
||||
newline is removed, and ‘\\’ must be used to quote the characters ‘\\’,
|
||||
‘$’, ‘‘’ and the first character of `word`.
|
||||
|
||||
Note that `word` itself does not undergo shell expansion. Backquotes
|
||||
in `word` do not have their usual effect; instead they behave
|
||||
similarly to double quotes, except that the backquotes themselves
|
||||
are passed through unchanged. (This information is given for
|
||||
completeness and it is not recommended that backquotes be used.)
|
||||
Quotes in the form `$’``...``’` have their standard effect of
|
||||
expanding backslashed references to special characters.
|
||||
Note that `word` itself does not undergo shell expansion. Backquotes in
|
||||
`word` do not have their usual effect; instead they behave similarly to
|
||||
double quotes, except that the backquotes themselves are passed through
|
||||
unchanged. (This information is given for completeness and it is not
|
||||
recommended that backquotes be used.) Quotes in the form $’`...`’ have
|
||||
their standard effect of expanding backslashed references to special
|
||||
characters.
|
||||
|
||||
If `<<-` is used, then all leading tabs are stripped from `word` and
|
||||
from the document.
|
||||
If \<\<- is used, then all leading tabs are stripped from `word` and
|
||||
from the document.
|
||||
|
||||
- `<<<` `word`
|
||||
Perform shell expansion on `word` and pass the result to standard
|
||||
input. This is known as a *here-string*. Compare the use of `word`
|
||||
in here-documents above, where `word` does not undergo shell
|
||||
expansion.
|
||||
\<\<\< `word`
|
||||
Perform shell expansion on `word` and pass the result to standard input.
|
||||
This is known as a *here-string*. Compare the use of `word` in
|
||||
here-documents above, where `word` does not undergo shell expansion. The
|
||||
result will have a trailing newline after it.
|
||||
|
||||
- `<&` `number`
|
||||
`>&` `number`
|
||||
The standard input/output is duplicated from file descriptor
|
||||
`number` (see man page dup2(2)).
|
||||
\<& `number`
|
||||
\>& `number`
|
||||
The standard input/output is duplicated from file descriptor `number`
|
||||
(see dup2(2)).
|
||||
|
||||
- `<& -`
|
||||
`>& -`
|
||||
Close the standard input/output.
|
||||
\<& -
|
||||
\>& -
|
||||
Close the standard input/output.
|
||||
|
||||
- `<& p`
|
||||
`>& p`
|
||||
The input/output from/to the coprocess is moved to the standard
|
||||
input/output.
|
||||
\<& p
|
||||
\>& p
|
||||
The input/output from/to the coprocess is moved to the standard
|
||||
input/output.
|
||||
|
||||
- `>&` `word`
|
||||
`&>` `word`
|
||||
(Except where ‘`>&` `word`’ matches one of the above syntaxes;
|
||||
‘`&>`’ can always be used to avoid this ambiguity.) Redirects
|
||||
both standard output and standard error (file descriptor 2) in the
|
||||
manner of ‘`>` `word`’. Note that this does *not* have the same
|
||||
effect as ‘`>` `word` `2>&1`’ in the presence of multios (see the
|
||||
section below).
|
||||
\>& `word`
|
||||
&> `word`
|
||||
(Except where ‘>& `word`’ matches one of the above syntaxes; ‘&>’ can
|
||||
always be used to avoid this ambiguity.) Redirects both standard output
|
||||
and standard error (file descriptor 2) in the manner of ‘> `word`’. Note
|
||||
that this does *not* have the same effect as ‘> `word` 2>&1’ in the
|
||||
presence of multios (see the section below).
|
||||
|
||||
- `>&|` `word`
|
||||
`>&!` `word`
|
||||
`&>|` `word`
|
||||
`&>!` `word`
|
||||
Redirects both standard output and standard error (file descriptor
|
||||
2) in the manner of ‘`>|` `word`’.
|
||||
\>&\| `word`
|
||||
\>&! `word`
|
||||
&>\| `word`
|
||||
&>! `word`
|
||||
Redirects both standard output and standard error (file descriptor 2) in
|
||||
the manner of ‘>\| `word`’.
|
||||
|
||||
- `>>&` `word`
|
||||
`&>>` `word`
|
||||
Redirects both standard output and standard error (file descriptor
|
||||
2) in the manner of ‘`>>` `word`’.
|
||||
\>\>& `word`
|
||||
&>\> `word`
|
||||
Redirects both standard output and standard error (file descriptor 2) in
|
||||
the manner of ‘>\> `word`’.
|
||||
|
||||
- `>>&|` `word`
|
||||
`>>&!` `word`
|
||||
`&>>|` `word`
|
||||
`&>>!` `word`
|
||||
Redirects both standard output and standard error (file descriptor
|
||||
2) in the manner of ‘`>>|` `word`’.
|
||||
\>\>&\| `word`
|
||||
\>\>&! `word`
|
||||
&>\>\| `word`
|
||||
&>\>! `word`
|
||||
Redirects both standard output and standard error (file descriptor 2) in
|
||||
the manner of ‘>\>\| `word`’.
|
||||
|
||||
If one of the above is preceded by a digit, then the file descriptor
|
||||
referred to is that specified by the digit instead of the default 0 or
|
||||
@ -137,7 +133,7 @@ referred to is that specified by the digit instead of the default 0 or
|
||||
shell evaluates each redirection in terms of the (*file descriptor*,
|
||||
*file*) association at the time of evaluation. For example:
|
||||
|
||||
> ... `1>``fname` `2>&1`
|
||||
> ... 1>`fname` 2>&1
|
||||
|
||||
first associates file descriptor 1 with file `fname`. It then associates
|
||||
file descriptor 2 with the file associated with file descriptor 1 (that
|
||||
@ -146,62 +142,58 @@ descriptor 2 would be associated with the terminal (assuming file
|
||||
descriptor 1 had been) and then file descriptor 1 would be associated
|
||||
with file `fname`.
|
||||
|
||||
The ‘`|&`’ command separator described in [Simple Commands &
|
||||
The ‘\|&’ command separator described in [Simple Commands &
|
||||
Pipelines](Shell-Grammar.html#Simple-Commands-_0026-Pipelines) is a
|
||||
shorthand for ‘`2>&1 |`’.
|
||||
shorthand for ‘2>&1 \|’.
|
||||
|
||||
The various forms of process substitution, ‘`<(``list``)`’, and
|
||||
‘`=(``list``)`’ for input and ‘`>(``list``)`’ for output, are often
|
||||
used together with redirection. For example, if `word` in an output
|
||||
redirection is of the form ‘`>(``list``)`’ then the output is piped to
|
||||
the command represented by `list`. See [Process
|
||||
Substitution](Expansion.html#Process-Substitution).
|
||||
The various forms of process substitution, ‘\<(`list`)’, and ‘=(`list`)’
|
||||
for input and ‘>(`list`)’ for output, are often used together with
|
||||
redirection. For example, if `word` in an output redirection is of the
|
||||
form ‘>(`list`)’ then the output is piped to the command represented by
|
||||
`list`. See [Process Substitution](Expansion.html#Process-Substitution).
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Opening-file-descriptors-using-parameters"></span>
|
||||
|
||||
## 7.1 Opening file descriptors using parameters
|
||||
|
||||
<span id="index-file-descriptors_002c-use-with-parameters"></span>
|
||||
<span id="index-parameters_002c-for-using-file-descriptors"></span>
|
||||
<span id="index-file-descriptors_002c-use-with-parameters"></span> <span
|
||||
id="index-parameters_002c-for-using-file-descriptors"></span>
|
||||
|
||||
When the shell is parsing arguments to a command, and the shell option
|
||||
`IGNORE_BRACES` is not set, a different form of redirection is allowed:
|
||||
IGNORE_BRACES is not set, a different form of redirection is allowed:
|
||||
instead of a digit before the operator there is a valid shell identifier
|
||||
enclosed in braces. The shell will open a new file descriptor that is
|
||||
guaranteed to be at least 10 and set the parameter named by the
|
||||
identifier to the file descriptor opened. No whitespace is allowed
|
||||
between the closing brace and the redirection character. For example:
|
||||
|
||||
> ... `{myfd}>&1`
|
||||
> ... {myfd}>&1
|
||||
|
||||
This opens a new file descriptor that is a duplicate of file descriptor
|
||||
1 and sets the parameter `myfd` to the number of the file descriptor,
|
||||
1 and sets the parameter myfd to the number of the file descriptor,
|
||||
which will be at least 10. The new file descriptor can be written to
|
||||
using the syntax `>&$myfd`. The file descriptor remains open in
|
||||
subshells
|
||||
using the syntax \>&$myfd. The file descriptor remains open in subshells
|
||||
|
||||
The syntax `{``varid``}>&-`, for example `{myfd}>&-`, may be used to
|
||||
close a file descriptor opened in this fashion. Note that the parameter
|
||||
given by `varid` must previously be set to a file descriptor in this
|
||||
case.
|
||||
The syntax {`varid`}>&-, for example {myfd}>&-, may be used to close a
|
||||
file descriptor opened in this fashion. Note that the parameter given by
|
||||
`varid` must previously be set to a file descriptor in this case.
|
||||
|
||||
It is an error to open or close a file descriptor in this fashion when
|
||||
the parameter is readonly. However, it is not an error to read or write
|
||||
a file descriptor using `<&$``param` or `>&$``param` if `param` is
|
||||
a file descriptor using \<&$`param` or \>&$`param` if `param` is
|
||||
readonly.
|
||||
|
||||
If the option `CLOBBER` is unset, it is an error to open a file
|
||||
descriptor using a parameter that is already set to an open file
|
||||
descriptor previously allocated by this mechanism. Unsetting the
|
||||
parameter before using it for allocating a file descriptor avoids the
|
||||
error.
|
||||
If the option CLOBBER is unset, it is an error to open a file descriptor
|
||||
using a parameter that is already set to an open file descriptor
|
||||
previously allocated by this mechanism. Unsetting the parameter before
|
||||
using it for allocating a file descriptor avoids the error.
|
||||
|
||||
Note that this mechanism merely allocates or closes a file descriptor;
|
||||
it does not perform any redirections from or to it. It is usually
|
||||
convenient to allocate a file descriptor prior to use as an argument to
|
||||
`exec`. The syntax does not in any case work when used around complex
|
||||
exec. The syntax does not in any case work when used around complex
|
||||
commands such as parenthesised subshells or loops, where the opening
|
||||
brace is interpreted as part of a command list to be executed in the
|
||||
current shell.
|
||||
@ -211,7 +203,7 @@ of a file descriptor:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
integer myfd
|
||||
exec {myfd}>~/logs/mylogfile.txt
|
||||
print This is a log message. >&$myfd
|
||||
@ -220,97 +212,96 @@ exec {myfd}>&-
|
||||
|
||||
</div>
|
||||
|
||||
Note that the expansion of the variable in the expression `>&$myfd`
|
||||
Note that the expansion of the variable in the expression \>&$myfd
|
||||
occurs at the point the redirection is opened. This is after the
|
||||
expansion of command arguments and after any redirections to the left on
|
||||
the command line have been processed.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Multios"></span>
|
||||
|
||||
## 7.2 Multios
|
||||
|
||||
<span id="index-multios"></span>
|
||||
<span id="index-MULTIOS_002c-use-of"></span>
|
||||
<span id="index-multios"></span> <span
|
||||
id="index-MULTIOS_002c-use-of"></span>
|
||||
|
||||
If the user tries to open a file descriptor for writing more than once,
|
||||
the shell opens the file descriptor as a pipe to a process that copies
|
||||
its input to all the specified outputs, similar to tee, provided the
|
||||
`MULTIOS` option is set, as it is by default. Thus:
|
||||
MULTIOS option is set, as it is by default. Thus:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
date >foo >bar
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
writes the date to two files, named ‘`foo`’ and ‘`bar`’. Note that a
|
||||
pipe is an implicit redirection; thus
|
||||
writes the date to two files, named ‘foo’ and ‘bar’. Note that a pipe is
|
||||
an implicit redirection; thus
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
date >foo | cat
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
writes the date to the file ‘`foo`’, and also pipes it to cat.
|
||||
writes the date to the file ‘foo’, and also pipes it to cat.
|
||||
|
||||
Note that the shell opens all the files to be used in the multio process
|
||||
immediately, not at the point they are about to be written.
|
||||
|
||||
Note also that redirections are always expanded in order. This happens
|
||||
regardless of the setting of the `MULTIOS` option, but with the option
|
||||
in effect there are additional consequences. For example, the meaning of
|
||||
the expression `>&1` will change after a previous redirection:
|
||||
regardless of the setting of the MULTIOS option, but with the option in
|
||||
effect there are additional consequences. For example, the meaning of
|
||||
the expression \>&1 will change after a previous redirection:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
date >&1 >output
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
In the case above, the `>&1` refers to the standard output at the start
|
||||
of the line; the result is similar to the `tee` command. However,
|
||||
In the case above, the \>&1 refers to the standard output at the start
|
||||
of the line; the result is similar to the tee command. However,
|
||||
consider:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
date >output >&1
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
As redirections are evaluated in order, when the `>&1` is encountered
|
||||
the standard output is set to the file `output` and another copy of the
|
||||
output is therefore sent to that file. This is unlikely to be what is
|
||||
intended.
|
||||
As redirections are evaluated in order, when the \>&1 is encountered the
|
||||
standard output is set to the file output and another copy of the output
|
||||
is therefore sent to that file. This is unlikely to be what is intended.
|
||||
|
||||
If the `MULTIOS` option is set, the word after a redirection operator is
|
||||
If the MULTIOS option is set, the word after a redirection operator is
|
||||
also subjected to filename generation (globbing). Thus
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
: > *
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
will truncate all files in the current directory, assuming there’s at
|
||||
least one. (Without the `MULTIOS` option, it would create an empty file
|
||||
called ‘`*`’.) Similarly, you can do
|
||||
least one. (Without the MULTIOS option, it would create an empty file
|
||||
called ‘\*’.) Similarly, you can do
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
echo exit 0 >> *.sh
|
||||
```
|
||||
|
||||
@ -319,16 +310,16 @@ echo exit 0 >> *.sh
|
||||
If the user tries to open a file descriptor for reading more than once,
|
||||
the shell opens the file descriptor as a pipe to a process that copies
|
||||
all the specified inputs to its output in the order specified, provided
|
||||
the `MULTIOS` option is set. It should be noted that each file is opened
|
||||
the MULTIOS option is set. It should be noted that each file is opened
|
||||
immediately, not at the point where it is about to be read: this
|
||||
behaviour differs from `cat`, so if strictly standard behaviour is
|
||||
needed, `cat` should be used instead.
|
||||
behaviour differs from cat, so if strictly standard behaviour is needed,
|
||||
cat should be used instead.
|
||||
|
||||
Thus
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
sort <foo <fubar
|
||||
```
|
||||
|
||||
@ -338,80 +329,78 @@ or even
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
sort <f{oo,ubar}
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
is equivalent to ‘`cat foo fubar | sort`’.
|
||||
is equivalent to ‘cat foo fubar \| sort’.
|
||||
|
||||
Expansion of the redirection argument occurs at the point the
|
||||
redirection is opened, at the point described above for the expansion of
|
||||
the variable in `>&$myfd`.
|
||||
the variable in \>&$myfd.
|
||||
|
||||
Note that a pipe is an implicit redirection; thus
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
cat bar | sort <foo
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
is equivalent to ‘`cat bar foo | sort`’ (note the order of the inputs).
|
||||
is equivalent to ‘cat bar foo \| sort’ (note the order of the inputs).
|
||||
|
||||
If the `MULTIOS` option is *un*set, each redirection replaces the
|
||||
previous redirection for that file descriptor. However, all files
|
||||
redirected to are actually opened, so
|
||||
If the MULTIOS option is *un*set, each redirection replaces the previous
|
||||
redirection for that file descriptor. However, all files redirected to
|
||||
are actually opened, so
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
echo Hello > bar > baz
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
when `MULTIOS` is unset will truncate ‘`bar`’, and write ‘`Hello`’ into
|
||||
‘`baz`’.
|
||||
when MULTIOS is unset will truncate ‘bar’, and write ‘Hello’ into ‘baz’.
|
||||
|
||||
There is a problem when an output multio is attached to an external
|
||||
program. A simple example shows this:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
cat file >file1 >file2
|
||||
cat file1 file2
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
Here, it is possible that the second ‘`cat`’ will not display the full
|
||||
contents of `file1` and `file2` (i.e. the original contents of `file`
|
||||
repeated twice).
|
||||
Here, it is possible that the second ‘cat’ will not display the full
|
||||
contents of file1 and file2 (i.e. the original contents of file repeated
|
||||
twice).
|
||||
|
||||
The reason for this is that the multios are spawned after the `cat`
|
||||
The reason for this is that the multios are spawned after the cat
|
||||
process is forked from the parent shell, so the parent shell does not
|
||||
wait for the multios to finish writing data. This means the command as
|
||||
shown can exit before `file1` and `file2` are completely written. As a
|
||||
workaround, it is possible to run the `cat` process as part of a job in
|
||||
shown can exit before file1 and file2 are completely written. As a
|
||||
workaround, it is possible to run the cat process as part of a job in
|
||||
the current shell:
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
{ cat file } >file >file2
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
Here, the `{``...``}` job will pause to wait for both files to be
|
||||
written.
|
||||
Here, the {`...`} job will pause to wait for both files to be written.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Redirections-with-no-command"></span>
|
||||
|
||||
@ -421,40 +410,40 @@ When a simple command consists of one or more redirection operators and
|
||||
zero or more parameter assignments, but no command name, zsh can behave
|
||||
in several ways.
|
||||
|
||||
<span id="index-NULLCMD_002c-use-of"></span>
|
||||
<span id="index-CSH_005fNULLCMD_002c-use-of"></span>
|
||||
<span id="index-NULLCMD_002c-use-of"></span> <span
|
||||
id="index-CSH_005fNULLCMD_002c-use-of"></span>
|
||||
|
||||
If the parameter `NULLCMD` is not set or the option `CSH_NULLCMD` is
|
||||
set, an error is caused. This is the csh behavior and `CSH_NULLCMD` is
|
||||
set by default when emulating csh.
|
||||
If the parameter NULLCMD is not set or the option CSH_NULLCMD is set, an
|
||||
error is caused. This is the csh behavior and CSH_NULLCMD is set by
|
||||
default when emulating csh.
|
||||
|
||||
<span id="index-SH_005fNULLCMD_002c-use-of"></span>
|
||||
|
||||
If the option `SH_NULLCMD` is set, the builtin ‘`:`’ is inserted as a
|
||||
If the option SH_NULLCMD is set, the builtin ‘:’ is inserted as a
|
||||
command with the given redirections. This is the default when emulating
|
||||
sh or ksh.
|
||||
|
||||
<span id="index-READNULLCMD_002c-use-of"></span>
|
||||
|
||||
Otherwise, if the parameter `NULLCMD` is set, its value will be used as
|
||||
a command with the given redirections. If both `NULLCMD` and
|
||||
`READNULLCMD` are set, then the value of the latter will be used instead
|
||||
of that of the former when the redirection is an input. The default for
|
||||
`NULLCMD` is ‘`cat`’ and for `READNULLCMD` is ‘`more`’. Thus
|
||||
Otherwise, if the parameter NULLCMD is set, its value will be used as a
|
||||
command with the given redirections. If both NULLCMD and READNULLCMD are
|
||||
set, then the value of the latter will be used instead of that of the
|
||||
former when the redirection is an input. The default for NULLCMD is
|
||||
‘cat’ and for READNULLCMD is ‘more’. Thus
|
||||
|
||||
<div class="example">
|
||||
|
||||
``` example
|
||||
```zsh
|
||||
< file
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
shows the contents of `file` on standard output, with paging if that is
|
||||
a terminal. `NULLCMD` and `READNULLCMD` may refer to shell functions.
|
||||
shows the contents of file on standard output, with paging if that is a
|
||||
terminal. NULLCMD and READNULLCMD may refer to shell functions.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
@ -25,7 +25,7 @@ This section of the manual provides some pointers to areas of the shell
|
||||
that are likely to be of particular interest to new users, and indicates
|
||||
where in the rest of the manual the documentation is to be found.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="When-the-shell-starts"></span>
|
||||
|
||||
@ -37,13 +37,13 @@ be created or edited to customize the shell. See
|
||||
|
||||
If no personal initialization files exist for the current user, a
|
||||
function is run to help you change some of the most common settings. It
|
||||
won’t appear if your administrator has disabled the `zsh/newuser`
|
||||
module. The function is designed to be self-explanatory. You can run it
|
||||
by hand with ‘`autoload -Uz zsh-newuser-install; zsh-newuser-install
|
||||
-f`’. See also [User Configuration
|
||||
won’t appear if your administrator has disabled the zsh/newuser module.
|
||||
The function is designed to be self-explanatory. You can run it by hand
|
||||
with ‘autoload -Uz zsh-newuser-install; zsh-newuser-install -f’. See
|
||||
also [User Configuration
|
||||
Functions](User-Contributions.html#User-Configuration-Functions).
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Interactive-Use"></span>
|
||||
|
||||
@ -56,15 +56,15 @@ Editor](Zsh-Line-Editor.html#Zsh-Line-Editor).
|
||||
The first decision a user must make is whether to use the Emacs or Vi
|
||||
editing mode as the keys for editing are substantially different. Emacs
|
||||
editing mode is probably more natural for beginners and can be selected
|
||||
explicitly with the command `bindkey -e`.
|
||||
explicitly with the command bindkey -e.
|
||||
|
||||
A history mechanism for retrieving previously typed lines (most simply
|
||||
with the Up or Down arrow keys) is available; note that, unlike other
|
||||
shells, zsh will not save these lines when the shell exits unless you
|
||||
set appropriate variables, and the number of history lines retained by
|
||||
default is quite small (30 lines). See the description of the shell
|
||||
variables (referred to in the documentation as parameters) `HISTFILE`,
|
||||
`HISTSIZE` and `SAVEHIST` in [Parameters Used By The
|
||||
variables (referred to in the documentation as parameters) HISTFILE,
|
||||
HISTSIZE and SAVEHIST in [Parameters Used By The
|
||||
Shell](Parameters.html#Parameters-Used-By-The-Shell). Note that it’s
|
||||
currently only possible to read and write files saving history when the
|
||||
shell is interactive, i.e. it does not work from scripts.
|
||||
@ -73,19 +73,18 @@ The shell now supports the UTF-8 character set (and also others if
|
||||
supported by the operating system). This is (mostly) handled
|
||||
transparently by the shell, but the degree of support in terminal
|
||||
emulators is variable. There is some discussion of this in the shell
|
||||
FAQ, `http://www.zsh.org/FAQ/`. Note in particular that for combining
|
||||
characters to be handled the option `COMBINING_CHARS` needs to be set.
|
||||
FAQ, <https://www.zsh.org/FAQ/>. Note in particular that for combining
|
||||
characters to be handled the option COMBINING_CHARS needs to be set.
|
||||
Because the shell is now more sensitive to the definition of the
|
||||
character set, note that if you are upgrading from an older version of
|
||||
the shell you should ensure that the appropriate variable, either `LANG`
|
||||
(to affect all aspects of the shell’s operation) or `LC_CTYPE` (to
|
||||
affect only the handling of character sets) is set to an appropriate
|
||||
value. This is true even if you are using a single-byte character set
|
||||
including extensions of ASCII such as `ISO-8859-1` or `ISO-8859-15`. See
|
||||
the description of `LC_CTYPE` in
|
||||
[Parameters](Parameters.html#Parameters).
|
||||
the shell you should ensure that the appropriate variable, either LANG
|
||||
(to affect all aspects of the shell’s operation) or LC_CTYPE (to affect
|
||||
only the handling of character sets) is set to an appropriate value.
|
||||
This is true even if you are using a single-byte character set including
|
||||
extensions of ASCII such as ISO-8859-1 or ISO-8859-15. See the
|
||||
description of LC_CTYPE in [Parameters](Parameters.html#Parameters).
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Completion-1"></span>
|
||||
|
||||
@ -95,14 +94,14 @@ Completion is a feature present in many shells. It allows the user to
|
||||
type only a part (usually the prefix) of a word and have the shell fill
|
||||
in the rest. The completion system in zsh is programmable. For example,
|
||||
the shell can be set to complete email addresses in arguments to the
|
||||
mail command from your `~/.abook/addressbook`; usernames, hostnames, and
|
||||
mail command from your \~/.abook/addressbook; usernames, hostnames, and
|
||||
even remote paths in arguments to scp, and so on. Anything that can be
|
||||
written in or glued together with zsh can be the source of what the line
|
||||
editor offers as possible completions.
|
||||
|
||||
Zsh has two completion systems, an old, so called `compctl` completion
|
||||
Zsh has two completion systems, an old, so called compctl completion
|
||||
(named after the builtin command that serves as its complete and only
|
||||
user interface), and a new one, referred to as `compsys`, organized as
|
||||
user interface), and a new one, referred to as compsys, organized as
|
||||
library of builtin and user-defined functions. The two systems differ in
|
||||
their interface for specifying the completion behavior. The new system
|
||||
is more customizable and is supplied with completions for many commonly
|
||||
@ -112,7 +111,7 @@ The completion system must be enabled explicitly when the shell starts.
|
||||
For more information see [Completion
|
||||
System](Completion-System.html#Completion-System).
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Extending-the-line-editor"></span>
|
||||
|
||||
@ -122,29 +121,28 @@ Apart from completion, the line editor is highly extensible by means of
|
||||
shell functions. Some useful functions are provided with the shell; they
|
||||
provide facilities such as:
|
||||
|
||||
- `insert-composed-char`
|
||||
composing characters not found on the keyboard
|
||||
insert-composed-char
|
||||
composing characters not found on the keyboard
|
||||
|
||||
- `match-words-by-style`
|
||||
configuring what the line editor considers a word when moving or
|
||||
deleting by word
|
||||
match-words-by-style
|
||||
configuring what the line editor considers a word when moving or
|
||||
deleting by word
|
||||
|
||||
- `history-beginning-search-backward-end`, etc.
|
||||
alternative ways of searching the shell history
|
||||
history-beginning-search-backward-end, etc.
|
||||
alternative ways of searching the shell history
|
||||
|
||||
- `replace-string`, `replace-pattern`
|
||||
functions for replacing strings or patterns globally in the command
|
||||
line
|
||||
replace-string, replace-pattern
|
||||
functions for replacing strings or patterns globally in the command line
|
||||
|
||||
- `edit-command-line`
|
||||
edit the command line with an external editor.
|
||||
edit-command-line
|
||||
edit the command line with an external editor.
|
||||
|
||||
See [ZLE Functions](User-Contributions.html#ZLE-Functions) for
|
||||
descriptions of these.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Options-3"></span>
|
||||
<span id="Options-1"></span>
|
||||
|
||||
## 3.3 Options
|
||||
|
||||
@ -153,7 +151,7 @@ These cover all aspects of the shell; browsing the full documentation is
|
||||
the only good way to become acquainted with the many possibilities. See
|
||||
[Options](Options.html#Options).
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Pattern-Matching"></span>
|
||||
|
||||
@ -168,22 +166,22 @@ Generation](Expansion.html#Filename-Generation).
|
||||
Of particular interest are the following patterns that are not commonly
|
||||
supported by other systems of pattern matching:
|
||||
|
||||
- `**`
|
||||
for matching over multiple directories
|
||||
\*\*
|
||||
for matching over multiple directories
|
||||
|
||||
- `|`
|
||||
for matching either of two alternatives
|
||||
\|
|
||||
for matching either of two alternatives
|
||||
|
||||
- `~`, `^`
|
||||
the ability to exclude patterns from matching when the
|
||||
`EXTENDED_GLOB` option is set
|
||||
\~, ^
|
||||
the ability to exclude patterns from matching when the EXTENDED_GLOB
|
||||
option is set
|
||||
|
||||
- `(``...``)`
|
||||
glob qualifiers, included in parentheses at the end of the pattern,
|
||||
which select files by type (such as directories) or attribute (such
|
||||
as size).
|
||||
(`...`)
|
||||
glob qualifiers, included in parentheses at the end of the pattern,
|
||||
which select files by type (such as directories) or attribute (such as
|
||||
size).
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="General-Comments-on-Syntax"></span>
|
||||
|
||||
@ -197,13 +195,13 @@ Grammar](Shell-Grammar.html#Shell-Grammar).
|
||||
|
||||
One commonly encountered difference is that variables substituted onto
|
||||
the command line are not split into words. See the description of the
|
||||
shell option `SH_WORD_SPLIT` in [Parameter
|
||||
shell option SH_WORD_SPLIT in [Parameter
|
||||
Expansion](Expansion.html#Parameter-Expansion). In zsh, you can either
|
||||
explicitly request the splitting (e.g. `${=foo}`) or use an array when
|
||||
you want a variable to expand to more than one word. See [Array
|
||||
explicitly request the splitting (e.g. ${=foo}) or use an array when you
|
||||
want a variable to expand to more than one word. See [Array
|
||||
Parameters](Parameters.html#Array-Parameters).
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Programming"></span>
|
||||
|
||||
@ -221,25 +219,25 @@ above, are provided with the shell and are described in [User
|
||||
Contributions](User-Contributions.html#User-Contributions). Features
|
||||
include:
|
||||
|
||||
- `promptinit`
|
||||
a prompt theme system for changing prompts easily, see [Prompt
|
||||
Themes](User-Contributions.html#Prompt-Themes)
|
||||
promptinit
|
||||
a prompt theme system for changing prompts easily, see [Prompt
|
||||
Themes](User-Contributions.html#Prompt-Themes)
|
||||
|
||||
- `zsh-mime-setup`
|
||||
a MIME-handling system which dispatches commands according to the
|
||||
suffix of a file as done by graphical file managers
|
||||
zsh-mime-setup
|
||||
a MIME-handling system which dispatches commands according to the suffix
|
||||
of a file as done by graphical file managers
|
||||
|
||||
- `zcalc`
|
||||
a calculator
|
||||
zcalc
|
||||
a calculator
|
||||
|
||||
- `zargs`
|
||||
a version of `xargs` that makes the `find` command redundant
|
||||
zargs
|
||||
a version of xargs that makes the find command redundant
|
||||
|
||||
- `zmv`
|
||||
a command for renaming files by means of shell patterns.
|
||||
zmv
|
||||
a command for renaming files by means of shell patterns.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -7,15 +7,15 @@
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
<span id="The-Z-Shell-Manual"></span>
|
||||
<span id="The-Z-Shell-Manual-1"></span>
|
||||
<span id="The-Z-Shell-Manual"></span> <span
|
||||
id="The-Z-Shell-Manual-1"></span>
|
||||
|
||||
# 1 The Z Shell Manual
|
||||
|
||||
This document has been produced from the texinfo file `zsh.texi`,
|
||||
included in the `Doc` sub-directory of the Zsh distribution.
|
||||
This document has been produced from the texinfo file zsh.texi, included
|
||||
in the Doc sub-directory of the Zsh distribution.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Producing-documentation-from-zsh_002etexi"></span>
|
||||
|
||||
@ -23,34 +23,34 @@ included in the `Doc` sub-directory of the Zsh distribution.
|
||||
|
||||
The texinfo source may be converted into several formats:
|
||||
|
||||
- The Info manual
|
||||
The Info format allows searching for topics, commands, functions,
|
||||
etc. from the many Indices. The command ‘`makeinfo zsh.texi`’ is
|
||||
used to produce the Info documentation.
|
||||
The Info manual
|
||||
The Info format allows searching for topics, commands, functions, etc.
|
||||
from the many Indices. The command ‘makeinfo zsh.texi’ is used to
|
||||
produce the Info documentation.
|
||||
|
||||
- The printed manual
|
||||
The command ‘`texi2dvi zsh.texi`’ will output `zsh.dvi` which can
|
||||
then be processed with dvips and optionally gs (Ghostscript) to
|
||||
produce a nicely formatted printed manual.
|
||||
The printed manual
|
||||
The command ‘texi2dvi zsh.texi’ will output zsh.dvi which can then be
|
||||
processed with dvips and optionally gs (Ghostscript) to produce a nicely
|
||||
formatted printed manual.
|
||||
|
||||
- The HTML manual
|
||||
An HTML version of this manual is available at the Zsh web site via:
|
||||
The HTML manual
|
||||
An HTML version of this manual is available at the Zsh web site via:
|
||||
|
||||
`http://zsh.sourceforge.net/Doc/`.
|
||||
<https://zsh.sourceforge.io/Doc/>.
|
||||
|
||||
(The HTML version is produced with texi2html, which may be obtained
|
||||
from `http://www.nongnu.org/texi2html/`. The command is ‘`texi2html
|
||||
–output . –ifinfo –split=chapter –node-files zsh.texi`’. If
|
||||
necessary, upgrade to version 1.78 of texi2html.)
|
||||
(The HTML version is produced with texi2html, which may be obtained from
|
||||
<http://www.nongnu.org/texi2html/>. The command is ‘texi2html –output .
|
||||
–ifinfo –split=chapter –node-files zsh.texi’. If necessary, upgrade to
|
||||
version 1.78 of texi2html.)
|
||||
|
||||
For those who do not have the necessary tools to process texinfo,
|
||||
precompiled documentation (PostScript, dvi, PDF, info and HTML formats)
|
||||
is available from the zsh archive site or its mirrors, in the file
|
||||
`zsh-doc.tar.gz`. (See [Availability](Introduction.html#Availability)
|
||||
for a list of sites.)
|
||||
zsh-doc.tar.gz. (See [Availability](Introduction.html#Availability) for
|
||||
a list of sites.)
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -3,17 +3,17 @@
|
||||
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
|
||||
|
||||
- [The Z Shell Manual](#the-z-shell-manual)
|
||||
- [Version 5.8](#version-58)
|
||||
- [Updated February 14, 2020](#updated-february-14-2020)
|
||||
- [Version 5.9](#version-59)
|
||||
- [Updated May 14, 2022](#updated-may-14-2022)
|
||||
- [The Z Shell Manual](#the-z-shell-manual-1)
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
# The Z Shell Manual
|
||||
|
||||
### Version 5.8
|
||||
### Version 5.9
|
||||
|
||||
### Updated February 14, 2020
|
||||
### Updated May 14, 2022
|
||||
|
||||
**Original documentation by Paul Falstad**
|
||||
|
||||
@ -32,7 +32,7 @@ permission notice identical to this one.
|
||||
Permission is granted to copy and distribute translations of this manual
|
||||
into another language, under the above conditions for modified versions.
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
<span id="Top"></span> <span id="The-Z-Shell-Manual-2"></span>
|
||||
|
||||
@ -46,7 +46,7 @@ compatible, either.
|
||||
|
||||
<span id="index-version"></span>
|
||||
|
||||
Version 5.8, last updated February 14, 2020.
|
||||
Version 5.9, last updated May 14, 2022.
|
||||
|
||||
— Indices —
|
||||
|
||||
@ -80,8 +80,8 @@ Zftp Function System
|
||||
|
||||
User Contributions
|
||||
|
||||
-----
|
||||
------------------------------------------------------------------------
|
||||
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user