HP-UX Reference (11i v1 05/09) - 1 User Commands N-Z (vol 2)

s
sh-bourne(1) sh-bourne(1)
( list ) Execute list in a sub-shell.
{ list ;} The purpose of using braces is to allow the aggregate output from list to be redirected else-
where. If redirection is used as in:
{ list;} >file
a subshell is created to execute list. This implies that any shell variables set, created, or
modified within the
{}
do not retain their values outside the {}. If no redirection is
used, a subshell is not created, and shell modifications made within the
{}are preserved.
name
() {list;}
Define a function which is referenced by name. The body of the function is the list of com-
mands between
{ and }. Execution of functions is described below (see ‘‘Execution’’).
The following words are recognized only as the first word of a command, and when not quoted:
if then else elif fi case esac for while until do done { }
Comments
A word beginning with # causes that word and all the following characters up to a new-line character to be
ignored.
Command Substitution
The standard output from a command enclosed in a pair of grave accents (``) can be used as part or all of
a word; trailing new-lines are removed.
Parameter Substitution
The
$ character is used to introduce substitutable parameters. There are two types of parameters, posi-
tional and keyword. If parameter is a digit, it is a positional parameter. Positional parameters can be
assigned values by
set. Keyword parameters (also known as variables) can be assigned values by writing:
name=value[ name=value ]...
Pattern-matching is not performed on value. Having a function and a variable with the same name is not
allowed.
${ parameter }
The value, if any, of the parameter is substituted. Braces are required only when parame-
ter is followed by a letter, digit, or underscore that is not to be interpreted as part of its
name. If parameter is
* or @, all positional parameters, starting with $1, are substituted
(separated by spaces). Parameter $0 is set from argument zero when the shell is invoked.
${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; the value of the parameter is then substi-
tuted. Positional parameters cannot be assigned to 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, the message ‘‘parameter null or not set’’ is printed.
${parameter:+word}
If parameter is set and is non-null, substitute word; otherwise substitute nothing.
In the above, word is not evaluated unless it is to be 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 whether parameter is set or
not.
The following parameters are automatically set by the shell:
# The number of positional parameters in decimal.
- Flags supplied to the shell on invocation or by the set command.
HP-UX 11i Version 1: September 2005 2 Hewlett-Packard Company Section 1883