ksh.1 (2010 09)
k
ksh(1) ksh(1)
The shell supports a limited one-dimensional array facility. An element of an array parameter is refer-
enced by a subscript. A subscript is denoted by a
[ followed by an arithmetic expression (see Arithmetic
Evaluation below) followed by a
]. To assign values to an array, use
set -A name value ... . The value
of all subscripts must be in the range of
0 through 1023. Arrays need not be declared. Any reference to
a named parameter with a valid subscript is legal and an array is created if necessary. Referencing an
array without a subscript is equivalent to referencing the first element.
The value of a named parameter can also be assigned by writing:
name
=value [name=value]...
If the
-i integer attribute is set for name, the value is subject to arithmetic evaluation as described
below.
Positional parameters, parameters denoted by a number, can be assigned values with the
set special
command. Parameter
$0 is set from argument zero when the shell is invoked.
The character
$ is used to introduce substitutable parameters .
${parameter } Substitute the value of the parameter, if any. Braces are required when
parameter is followed by a letter, digit, or underscore that should not be inter-
preted as part of its name or when a named parameter is subscripted.
If parameter is one or more digits, it is a positional parameter. A positional
parameter of more than one digit must be enclosed in braces. If parameter is
* or @, all the positional parameters, starting with $1, are substituted
(separated by a field separator character). If an array identifier with subscript
* or @ is used, the value for each element is substituted (separated by a field
separator character). The shell reads all the characters from ${ to the
matching } as part of the same word even if it contains braces or metacharac-
ters.
${#parameter } If parameter is * or @, the number of positional parameters is substituted.
Otherwise, the length of the value of the parameter is substituted.
${#identifier [*]} Substitute the number of elements in the array identifier.
${parameter :-word }
If parameter is set and is non-null, substitute its value; otherwise substitute
word.
${parameter :=word }
If parameter is not set or is null, set it to word; then substitute the value of the
parameter. Positional parameters cannot be assigned in this way.
${parameter :?word }
If parameter is set and is non-null, substitute its value; otherwise, print word
and exit from the shell. If word is omitted, a standard message is printed.
${parameter :+word }
If parameter is set and is non-null, substitute word; otherwise substitute noth-
ing.
${parameter #pattern }
${parameter ##pattern }
If the shell pattern matches the beginning of the value of parameter , the value
of this substitution is the value of the parameter with the matched portion
deleted; otherwise the value of this parameter is substituted. In the former
case, the smallest matching pattern is deleted; in the latter case, the largest
matching pattern is deleted.
${parameter %pattern }
${parameter %%pattern }
If the shell pattern matches the end of the value of parameter , the value of
parameter with the matched part is deleted; otherwise substitute the value of
parameter . In the former, the smallest matching pattern is deleted; in the
latter, the largest matching pattern is deleted.
In the above, word is not evaluated unless it is used as the substituted string. Thus, in the following
example,
pwd is executed only if d is not set or is null:
4 Hewlett-Packard Company − 4 − HP-UX 11i Version 3: September 2010