Go to the previous, next section.
A parameter has a name, a value, and a number of attributes. A name may
be any sequence of alphanumeric characters and _
's, or the single
characters *
, @
, #
, ?
, -
, $
,
or !
. The value may be either 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.
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. The elements
are numbered beginning with 1. 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 n'th 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
.
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 parenthesis the string up to the matching closing parenthesis is considered to be a list of flags. The possible flags are:
e
w
s:string:
w
flag).
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 returns the last match.
i
r
, but returns the index of the match. This may not be
combined with a second argument.
I
i
, but returns the index of the last match.
n:expr:
r
, R
, i
, or I
, makes them
return the n'th or n'th last match (assuming 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 n'th positional parameter. The
parameters *
, @
, and argv
are arrays containing
all the positional parameters; thus argv[n]
, is equivalent
to simply n.
The following parameters are automatically set by the shell:
!
#
ARGC
#
.
þ
$
-
set
or
setopt
commands.þ
*
argv
*
.
þ
@
argv[@]
.
þ
?
status
?
.
þ
_
EGID
EUID
ERRNO
errno
as set by the most recently failed system
call. This value is system dependent and is intended for debugging
purposes.þ
GID
HOST
HOSTTYPE
LINENO
OLDPWD
OPTARG
getopts
command.þ
OPTIND
getopts
command.þ
PPID
PWD
RANDOM
RANDOM
.þ
SECONDS
SHLVL
signals
TTY
UID
USERNAME
LOGNAME
VERSION
zsh
.
The following parameters are used by the shell:
ARGV
BAUD
cdpath (CDPATH)
cd
command.þ
COLUMNS
DIRSTACKSIZE
AUTO_PUSHD
option.þ
FCEDIT
fc
builtin.
þ
þ
fignore (FIGNORE)
fpath (FPATH)
-u
attribute is referenced. If an executable file is
found, then it is read and executed in the current environment.þ
HISTCHARS
!
). The second character signals the start
of a quick history substitution (default ^
). The third character
is the comment character (default #
).þ
HISTFILE
HISTSIZE
HOME
cd
command.
þ
IFS
read
builtin.þ
KEYTIMEOUT
LINES
LISTMAX
LITHISTSIZE
LOGCHECK
watch
parameter.þ
MAIL
mailpath
is not set, the shell looks
for mail in the specified file. By default it is set to the user's
system mailbox.þ
MAILCHECK
mailpath (MAILPATH)
?
and a message that will be
printed. The sequence $_
in the message will be replaced by the
name of the mail file. 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 (MANPATH)
manpath
array can be useful, however, since setting it also
sets MANPATH
, and vice versa.þ
þ
þ
þ
NULLCMD
cat
. For sh/ksh-like behavior, change this
to :
. For csh-like behavior, unset this parameter; the shell will
print an error message if null commands are entered.þ
þ
path (PATH)
POSTEDIT
PROMPT
%
and the next character of the
sequence. The following escape sequences are recognized:
%d
%/
$PWD
).
%~
$PWD
. If it has a named directory as its prefix, that part is
replaced by a ~
followed by the name of the directory. If it
starts with $HOME
, that part is replaced by a ~
.
%c
%.
%C
$PWD
. An integer may follow the %
to get more than one component. Unless %C
is used, tilde
expansion is performed first.
!
%h
%!
%M
%m
%
to
specify how many components of the hostname are desired.
%S (%s)
%U (%u)
%B (%b)
%t
%@
%T
%*
%n
$USERNAME
.
%w
%W
%D
%D{string}
strftime
function. See
strftime(3)
for more details, if your system has it.
%l
%?
%_
if
and
for
) that have been started on the command line. If given an
integer number, that many strings will be printed.
%E
ALWAYS_LAST_PROMPT
set.
%#
#
if the shell is running as root, a %
if not.
Equivalent to %(#.#.%%)
%v
psvar
array parameter.
Following the %
with an integer gives that element of the
array.
%{...%}
%(x.true-text.false-text)
x
is
arbitrary; the same character is used to separate the text for the true
result from that for the false result. Both the separator and the right
parenthesis may be escaped with a backslash. 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. The text character x
may be any of the following:
c
.
~
/
C
t
T
d
D
w
?
#
g
L
SHLVL
parameter is at least n.
S
SECONDS
parameter is at least n.
v
psvar
has at least n elements.
_
PROMPT
. The default is `> '.þ
select
loop. Recognizes the same
escape sequences as PROMPT
. The default is `?# '.þ
PROMPT
, PROMPT2
, PROMPT3
, and PROMPT4
,
respectively.þ
þ
PROMPT
strings. Setting psvar
also sets PSVAR
, and
vice versa.þ
PROMPT
.
þ
more
.þ
SINGLE_LINE_ZLE
option is set. Recognizes the same escape
sequences as PROMPT
.þ
%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
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.
þ
time
keyword. The
default is `%E real %U user %S system %P %J'. Recognizes the
following escape sequences:
%U
%S
%E
%P
%W
%X
%D
%K
%M
%F
%R
%I
%O
%r
%s
%k
%w
%c
%J
$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.þ
watch
parameter is set.
Default is `%n has %a %l from %m'. Recognizes the following escape
sequences:
%n
%a
%l
%M
%m
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
%W
%D
%(x:true-text:false-text)
x
is
arbitrary; the same character is used to separate the text for the true
result from that for the false result. Both the separator and the right
parenthesis may be escaped with a backslash. Ternary expressions may be
nested.
The test character x
may be any one of 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 result 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 always be present.
$HOME
.
Go to the previous, next section.