HP-UX Reference (11i v2 03/08) - 1 User Commands A-M (vol 1)

k
ksh(1) ksh(1)
for identifier [ in word ... ]
do list done
Each time for is executed, identifier is set to the next word taken from the
in word
list. If
in word ... is omitted, for
executes the do list once for each positional parame-
ter set (see Parameter Substitution below). Execution ends when there are no more
words in the list.
select identifier [ in word... ]
do list done
A select command prints on standard error (file descriptor 2), the set of words, each
preceded by a number. If
in word ... is omitted, the positional parameters are used
instead (see Parameter Substitution below). The
PS3 prompt is printed and a line is
read from the standard input. If this line starts with the number of one of the listed
words, the value of the parameter identifier is set to the word corresponding to this
number. If this line is empty, the selection list is printed again. Otherwise the value of
the parameter identifier is set to null. The contents of the line read from standard input
is saved in the parameter
REPLY. The list is executed for each selection until a
break
or end-of-file (eof) is encountered.
case word in [[ ( ] pattern [ | pattern ] ... )
list ;; ] ... esac
A case command executes the list associated with the first pattern that matches word.
The form of the patterns is identical to that used for file name generation (see File Name
Generation below).
if list then list [ elif list then list ] ... [ else list ] fi
The list following if is executed and, if it returns a zero exit status, the list following
the first then is executed. Otherwise, the list following elif is executed and, if its
value is zero, the list following the next then is executed. Failing that, the
else list is
executed. If no
else list or then list is executed, if returns a zero exit status.
while list do list done
until list do list done
A while command repeatedly executes the while list, and if the exit status of the last
command in the list is zero, executes the do list; otherwise the loop terminates. If no
commands in the do list are executed, while returns a zero exit status; until can be
used in place of while to negate the loop termination test.
( list ) Execute list in a separate environment. If two adjacent open parentheses are needed for
nesting, a space must be inserted to avoid arithmetic evaluation as described below.
{ list ;} Execute list, but not in a separate environment. Note that { is a keyword and requires
a trailing blank to be recognized.
[[ expression ]]
Evaluates expression and returns a zero exit status when expression is true. See Condi-
tional Expressions below, for a description of expression . Note that [[ and ]] are key-
words and require blanks between them and expression .
function identifier { list ;}
identifier () { list ;}
Define a function referred to by identifier. The body of the function is the list of com-
mands between { and } (see Functions below).
time pipeline pipeline is executed and the elapsed time, user time, and system time are printed on
standard error. Note that the time keyword can appear anywhere in the pipeline to
time the entire pipeline. To time a particular command in a pipeline , see time(1).
The following keywords 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 { } function select time [[ ]]
Comments
A word beginning with # causes that word and all subsequent characters up to a new-line to be ignored.
Aliasing
The first word of each command is replaced by the text of an alias, if an alias for this word has been
defined. An alias name consists of any number of characters excluding metacharacters, quoting charac-
ters, file expansion characters, parameter and command substitution characters, and
=. The replacement
string can contain any valid shell script, including the metacharacters listed above. The first word of
Section 1404 Hewlett-Packard Company 2 HP-UX 11i Version 2: August 2003