HP-UX Reference (11i v1 05/09) - 1 User Commands N-Z (vol 2)
s
sh-posix(1) sh-posix(1)
If the -i integer attribute is set for name, the value is subject to arithmetic evaluation.
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.
Use the prefix character
$ to specify the value of a parameter for substitution.
$parameter
${parameter}
${
parameter[subscript]}
Substitute the value of the parameter, if any. Braces are required when parameter is fol-
lowed 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 posi-
tional parameter. A positional parameter of more than one digit must be enclosed in
braces. The shell reads all the characters from
${ to the matching } as part of the same
word, even if it contains braces or metacharacters.
If parameter is
* or @, all the positional parameters, starting with
1, are substituted
(separated by a field separator character). See the "Quoting" subsection.
If an array parameter with subscript
* or @ is used, the value for each element is substi-
tuted (separated by a field separator character).
${#parameter}
If parameter is * or @, the number of positional parameters is substituted. Otherwise, the
length of the value of the parameter is substituted.
${#parameter[*]}
Substitute the number of elements in the array.
${parameter:-word}
If parameter is set and is nonnull, 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 may not be assigned in this way.
${parameter:?word}
If parameter is set and is nonnull, 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 nonnull, substitute word; otherwise, substitute nothing.
${parameter#pattern}
${
parameter##pattern}
If the shell pattern matches the beginning of the value of parameter, the value of this sub-
stitution 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. These characters # or %
should be escaped by a backslash (\) or quotes (’’).
${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. These characters # or % should be escaped by a backslash (\) or quotes (’’).
In the above, word is not evaluated unless it is used as the substituted string. Thus, in the following exam-
ple, 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.
• The following parameters are set automatically by the shell:
0 The string used to call the command or script, set from invocation argument zero.
Section 1−−904 Hewlett-Packard Company − 13 − HP-UX 11i Version 1: September 2005