Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
User Commands (k - l) ksh(1)
In addition, tilde substitution is attempted when the value of a variable assignment parameter
begins with a tilde.
Command Substitution
The standard output from a command enclosed in parentheses preceded by a dollar sign $( ) or a
pair of ‘‘ (grave accents) can be used as part or all of a word; trailing newlines are removed. In
the second (archaic) form, the string between the grave accents is processed for special quoting
characters before the command is executed. (See Quoting.) The command substitution $(cat
file) can be replaced by the equivalent but faster $(<file). Command substitution of most special
commands that do not perform input/output redirection are carried out without creating a
separate process. An arithmetic expression enclosed in double parentheses preceded by a dollar
sign ( $(( )) ) is replaced by the value of the arithmetic expression within the double parentheses.
Parameter Substitution
A parameter is an identifier, one or more digits, or any of the characters *, @@@@, #, ?, -, $,
and !.Anamed parameter (a parameter denoted by an identifier) has a value and 0 (zero) or
more attributes. Named parameters can be assigned values and attributes by using the typeset
special command. The attributes supported by the shell are described later with the typeset spe-
cial command. Exported parameters pass values and attributes to the environment.
The shell supports a 1-dimensional array facility. An element of an array parameter is referenced
by a subscript. A subscript is denoted by an arithmetic expression enclosed with [ ] (brackets).
To assign values to an array, use values of subscripts in the range of 0 to 1023. Arrays need not
be declared. Any reference to a named parameter with a valid subscript is legal and an array will
be created if necessary. Referencing an array without a subscript is equivalent to referencing the
element 0 (zero).
The value of a named parameter can be assigned by the following:
name=value [ name=value ]
If the integer attribute, -i, is set for name, the value is subject to arithmetic evaluation. Positional
parameters, which are denoted by a number, can be assigned values with the set special com-
mand. Parameter $0 is set from argument 0 (zero) when the shell is invoked. The $ (dollar sign)
character is used to introduce substitutable parameters.
${parameter}
Reads all the characters from the ${ (dollar sign left brace) to the matching } (right
brace) as part of the same word even if it contains braces or metacharacters. The value,
if any, of the parameter is substituted. The braces are required when parameter is fol-
lowed by a letter, digit, or underscore that is not to be interpreted as part of its name or
when a named parameter is subscripted. If parameter is one or more digits, it is a posi-
tional parameter. A positional parameter of more than one digit must be enclosed in
braces. If parameter is * (asterisk) or @@@@ (at sign), 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 of the elements is
substituted (separated by a field separator character).
${#parameter}
Substitutes the number of positional parameters if parameter is * or @@@@; other-
wise, the length of the value of the parameter is substituted.
${#identifier[*]}
Substitutes the number of elements in the array identifier.
527188-003 Hewlett-Packard Company 5−11