HP-UX Reference (11i v3 07/02) - 1 User Commands N-Z (vol 2)

s
sh-posix(1) sh-posix(1)
${#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.
1, 2, ... The positional parameters.
*, @ All the set positional parameters, separated by a field separator character. See the Quoting
subsection.
# The number of set positional parameters in decimal.
- Flags supplied to the shell on invocation or by the set command.
? The decimal exit status returned by the last executed command.
$ The process number of this shell.
_ Initially, the absolute path name of the shell or script being executed, as passed in the
environment. Subsequently, it is assigned the last argument of the previous command.
This parameter is not set for commands which are asynchronous. This parameter is also
used to hold the name of the matching
MAIL file when checking for mail.
! The process number of the last background command invoked.
ERRNO The value of errno as set by the most recently failed system call. This value is system-
dependent and is intended for debugging purposes.
LINENO The line number of the current line within the script or function being executed.
HP-UX 11i Version 3: February 2007 13 Hewlett-Packard Company 255