MPE/iX Shell and Utilities Reference Manual, Vol 2

sh(1) MPE/iX Shell and Utilities sh(1)
$? expands to the exit status of the last command executed.
$$ expands to the process number of the original parent shell.
$! expands to the process number of the last asynchronous command.
These constructs are called parameters of the shell. They include the positional parameters,
but are not restricted to the positional parameters.
We have already mentioned that you can expand a parameter by putting a $ in front of the
parameter name. More sophisticated ways to expand parameters are:
${parameter}
expands any parameter.
${number}
expands to the positional parameter with the given number. (When using $d to refer
to the dth positional parameter, d must be a single digit; with brace brackets, number
can be greater than nine.) Since braces mark the beginning and end of the name, you
can immediately follow the expression with a letter or digit.
${variable[arithmetic expression]}
expands to the value of an element in an array named variable. The arithmetic
expression gives the subscript of the array. (See Arithmetic Substitution.)
${variable[]}
expands to all elements in the array variable, separated by the first character in
IFS
.
${variable[@]}
when unquoted, is the same as ${variable[]}. When quoted as "${vari-
able[@]}", it expands to all the elements in the array variable, each quoted individ-
ually.
${#parameter}
expands to the number of characters in the value of the given parameter.
${#}, ${#@}
expands to the number of positional parameters.
${#variable[]}
expands to the number of elements in the array named variable. Elements that do not
have assigned values do not count. For example, if you only assign values to ele-
ments 0 and 4, the number of elements is 2. Elements 1 through 3 do not count.
${parameter:–word}
expands to the value of parameter if it is defined and has a non-empty value; other-
wise, it expands word. This means that you can use word as a default value if the
parameter isn’t defined.
Commands and Utilities 1-531