A parameter has a name, a value, and a number of attributes.
A name may be any sequence of alphanumeric
characters and underscores, or the single characters
`*
', `@
', `#
', `?
', `-
', `$
', or `!
'.
The value may be a scalar (a string),
an integer, or an array.
To assign a scalar or integer value to a parameter,
use the typeset
builtin.
To assign an array value, use `set -A
name value ...'.
The value of a parameter may also be assigned by writing:
name=
value
If the integer attribute, -i
, is set for name,
the value is subject to arithmetic evaluation.
In the parameter lists, the mark `<S>' indicates that the parameter is special.
Special parameters cannot have their type changed, and they stay special even
if unset. `<Z>' indicates that the parameter does not exist when the shell
initialises in sh
or ksh
emulation mode.
Shell function executions delimit scopes for shell parameters.
(Parameters are dynamically scoped.) The typeset
builtin, and its
alternative forms declare
, integer
, local
and readonly
(but not export
), can be used to declare a parameter as being local
to the innermost scope.
When a parameter is read or assigned to, the
innermost existing parameter of that name is used. (That is, the
local parameter hides any less-local parameter.) However, assigning
to a non-existent parameter, or declaring a new parameter with export
,
causes it to be created in the outermost scope.
Local parameters disappear when their scope ends.
unset
can be used to delete a parameter while it is still in scope; this
will reveal the next outer parameter of the same name. However, special
parameters are still special when unset.
The value of an array parameter may be assigned by writing:
name=(
value ...)
Individual elements of an array may be selected using a
subscript. A subscript of the form `[
exp]
'
selects the single element exp, where exp is
an arithmetic expression which will be subject to arithmetic
expansion as if it were surrounded by `$((
...))
'.
The elements are numbered beginning with 1 unless the
KSH_ARRAYS
option is set when they are numbered from zero.
A subscript of the form `[*]
' or `[@]
' evaluates to all
elements of an array; there is no difference between the two
except when they appear within double quotes.
`"$foo[*]"
' evaluates to `"$foo[1] $foo[2]
..."
', while
`"$foo[@]"
' evaluates to `"$foo[1]" "$foo[2]"
', etc.
A subscript of the form `[
exp1,
exp2]
'
selects all elements in the range exp1 to exp2,
inclusive.
If one of the subscripts evaluates to a negative number,
say -
n, then the nth element from the end
of the array is used. Thus `$foo[-3]
' is the third element
from the end of the array foo
, and
`$foo[1,-1]
' is the same as `$foo[*]
'.
Subscripting may also be performed on non-array values, in which
case the subscripts specify a substring to be extracted.
For example, if FOO
is set to `foobar
', then
`echo $FOO[2,5]
' prints `ooba
'.
Subscripts may be used inside braces used to delimit a parameter name, thus
`${foo[2]}
' is equivalent to `$foo[2]
'. If the KSH_ARRAYS
option is set, the braced form is the only one that will
work, the subscript otherwise not being treated specially.
If a subscript is used on the left side of an assignment the selected range is replaced by the expression on the right side.
If the opening bracket or the comma is directly followed by an opening parentheses the string up to the matching closing one is considered to be a list of flags. The flags currently understood are:
e
w
s:
string:
w
flag).
p
print
builtin in
the string argument of a subsequent `s
' flag.
f
pws:\n:
'.
r
w
' flag is given, respectively); note that this is like giving a
number: `$foo[(r)
??,3]
' and `$foo[(r)
??,(r)f*]
' work.
R
r
', but gives the last match.
i
r
', but gives the index of the match instead; this may not
be combined with a second argument.
I
i
, but gives the index of the last match.
n:
expr:
r
', `R
', `i
' or `I
', makes them give
the nth or nth last match (if expr evaluates to
n).
Positional parameters are set by the shell on invocation,
by the set
builtin, or by direct assignment.
The parameter n, where n is a number,
is the nth positional parameter.
The parameters *
, @
and argv
are
arrays containing all the positional parameters;
thus `$argv[
n]
', etc., is equivalent to simply `$
n'.
The following parameters are automatically set by the shell:
!
<S>
#
<S>
ARGC
<S> <Z>
#
.
$
<S>
-
<S>
set
or setopt
commands.
*
<S>
argv
<S> <Z>
*
.
@
<S>
argv[@]
.
?
<S>
0
<S>
FUNCTION_ARGZERO
option
is set, this is set temporarily within a shell function to the name of the
function, and within a sourced script to the name of the script.
status
<S> <Z>
?
.
_
<S>
EGID
<S>
(EGID=
gid; command)
'
EUID
<S>
(EUID=
uid; command)
'
ERRNO
<S>
GID
<S>
(GID=
gid; command)
'
HOST
LINENO
<S>
LOGNAME
typeset
builtin.
MACHTYPE
OLDPWD
OPTARG
<S>
getopts
command.
OPTIND
<S>
getopts
command.
OSTYPE
PPID
<S>
PWD
RANDOM
<S>
RANDOM
.
SECONDS
<S>
SHLVL
<S>
signals
TTY
TTYIDLE
<S>
UID
<S>
(UID=
uid; command)
'
USERNAME
<S>
(USERNAME=
username; command)
'
VENDOR
ZSH_NAME
ZSH_VERSION
The following parameters are used by the shell:
ARGV0
argv[0]
of external commands.
Usually used in constructs like `ARGV0=emacs nethack
'.
BAUD
cdpath
<S> <Z> (CDPATH
<S>)
cd
command.
COLUMNS
<S>
DIRSTACKSIZE
AUTO_PUSHD
option.
FCEDIT
fc
builtin.
fignore
<S> <Z> (FIGNORE
<S>)
fpath
<S> <Z> (FPATH
<S>)
-u
attribute is referenced. If an executable
file is found, then it is read and executed in the current environment.
histchars
<S>
!
'). The second character signals the
start of a quick history substitution (default `^
'). The third
character is the comment character (default `#
').
HISTCHARS
<S> <Z>
histchars
. (Deprecated.)
HISTFILE
HISTSIZE
<S>
HOME
<S>
cd
command.
IFS
<S>
read
builtin. Any characters from the set space, tab and
newline that appear in the IFS are called IFS white space.
One or more IFS white space characters or one non-IFS white space
character together with any adjacent IFS white space character delimit
a field. If an IFS white space character appears twice consecutively
in the IFS, this character is treated as if it were not an IFS white
space character.
KEYTIMEOUT
LANG
<S>
LC_
'.
LC_ALL
<S>
LANG
' variable and the value
of any of the other variables starting with `LC_
'.
LC_COLLATE
<S>
LC_CTYPE
<S>
LC_MESSAGES
<S>
LC_TIME
<S>
LINES
<S>
LISTMAX
LOGCHECK
watch
parameter.
MAIL
mailpath
is not set,
the shell looks for mail in the specified file.
MAILCHECK
mailpath
<S> <Z> (MAILPATH
<S>)
?
' and a
message that will be printed. The message will undergo
parameter expansion, command substitution and arithmetic
substitution with the variable $_
defined as the name
of the file that has changed. The default message is
`You have new mail
'. If an element is a directory
instead of a file the shell will recursively check every
file in every subdirectory of the element.
manpath
<S> <Z> (MANPATH
<S> <Z>)
manpath
array can be useful, however, since setting it also sets
MANPATH
, and vice versa.
module_path
<S> <Z> (MODULE_PATH
<S>)
zmodload
searches for dynamically loadable modules.
This is initialised to a standard pathname,
usually `/usr/local/lib/zsh/$ZSH_VERSION
'.
(The `/usr/local/lib
' part varies from installation to installation.)
For security reasons, any value set in the environment when the shell
is started will be ignored.
These parameters only exist if the installation supports dynamic
module loading.
NULLCMD
<S>
cat
. For sh/ksh
behavior, change this to :
. For csh-like
behavior, unset this parameter; the shell will print an
error message if null commands are entered.
path
<S> <Z> (PATH
<S>)
POSTEDIT
<S>
PS1
<S>
%m%#
'. It undergoes a special form of expansion
before being displayed; see section Prompt Expansion.
PS2
<S>
PS1
.
The default is `%_>
', which displays any shell constructs or quotation
marks which are currently being processed.
PS3
<S>
select
loop.
It is expanded in the same way as PS1
.
The default is `?#
'.
PS4
<S>
+
'.
PROMPT
<S> <Z>
PROMPT2
<S> <Z>
PROMPT3
<S> <Z>
PROMPT4
<S> <Z>
PS1
, PS2
, PS3
and PS4
,
respectively.
psvar
<S> <Z> (PSVAR
<S>)
PROMPT
strings. Setting psvar
also sets PSVAR
, and
vice versa.
prompt
<S> <Z>
PS1
.
READNULLCMD
<S>
more
.
REPORTTIME
RPROMPT
<S>
RPS1
<S>
SINGLELINEZLE
option is set.
It is expanded in the same way as PS1
.
SAVEHIST
SPROMPT
<S>
%R
' expands to the string which presumably needs spelling
correction, and `%r
' expands to the proposed correction.
All other prompt escapes are also allowed.
STTY
stty
command with the value of this parameter as arguments in order to
set up the terminal before executing the command. The modes apply only to the
command, and are reset when it finishes or is suspended. If the command is
suspended and continued later with the fg
or wait
builtins it will
see the modes specified by STTY
, as if it were not suspended. This
(intentionally) does not apply if the command is continued via `kill -CONT
'.
STTY
is ignored if the command is run in the background, or if it is in the
environment of the shell but not explicitly assigned to in the input line. This
avoids running stty at every external command by accidentally exporting it.
Also note that STTY
should not be used for window size specifications; these
will not be local to the command.
TERM
<S>
TIMEFMT
time
keyword.
The default is `%E real %U user %S system %P %J
'.
Recognizes the following escape sequences:
%%
%
'.
%U
%S
%E
%P
%U
+%S
)/%E
.
%J
:
mm:
ss.
ttt'
format (hours and minutes are only printed if they are not zero).
TMOUT
ALRM
signal if a command is not entered within the specified number of
seconds after issuing a prompt. If there is a trap on SIGALRM
, it
will be executed and a new alarm is scheduled using the value of the
TMOUT
parameter after executing the trap. If no trap is set, and
the idle time of the terminal is not less than the value of the
TMOUT
parameter, zsh terminates. Otherwise a new alarm is
scheduled to TMOUT
seconds after the last keypress.
TMPPREFIX
/tmp/zsh
'.
watch
<S> <Z> (WATCH
<S>)
all
', then all login/logout events
are reported. If it contains the single word `notme
', then all
events are reported as with `all
' except $USERNAME
.
An entry in this list may consist of a username,
an `@
' followed by a remote hostname,
and a `%
' followed by a line (tty).
Any or all of these components may be present in an entry;
if a login/logout event matches all of them,
it is reported.
WATCHFMT
watch
parameter is set.
Default is `%n has %a %l from %m
'.
Recognizes the following escape sequences:
%n
%a
%l
%M
%m
.
'. If only the
IP address is available or the utmp field contains
the name of an X-windows display, the whole name is printed.
NOTE:
The `%m
' and `%M
' escapes will work only if there is a host name
field in the utmp on your machine. Otherwise they are
treated as ordinary strings.
%S
(%s
)
%U
(%u
)
%B
(%b
)
%t
%@
%T
%w
-
dd' format.
%W
/
dd/
yy' format.
%D
-
mm-
dd' format.
%(
x:
true-text:
false-text)
l
', `n
', `m
'
or `M
', which indicate a `true' result if the corresponding
escape sequence would return a non-empty value; or it may be `a
',
which indicates a `true' result if the watched user has logged in,
or `false' if he has logged out.
Other characters evaluate to neither true nor false; the entire
expression is omitted in this case.
If the result is `true', then the true-text
is formatted according to the rules above and printed,
and the false-text is skipped.
If `false', the true-text is skipped and the false-text
is formatted and printed.
Either or both of the branches may be empty, but
both separators must be present in any case.
WORDCHARS
<S>
ZDOTDIR
$HOME
.
Go to the first, previous, next, last section, table of contents.