ksh(1)

ksh(1)

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 ®rst element.

The value of a named parameter can also be assigned by writing:

name=value [ name=value ] ...

If the -iinteger 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 com- mand. 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 interpreted 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 ®eld separator character). If an array identi®er with subscript * or @ is used, the value for each element is substituted (separated by a ®eld separator character). The shell reads all the characters from ${ to the matching } as part of the same word even if it contains braces or metacharacters.

${#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 identi®er.

${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 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:

echo ${d:-$(pwd)}

If the colon (:) is omitted from the above expressions, the shell only checks to determine whether or not parameter is set.

k

HP-UX Release 11i: December 2000

− 4 −

Section 1399