ksh(1)

ksh(1)

for identifier

[ in word ... ] do list done

 

Each time for is executed, identi®er 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 parameter set

 

(see Parameter Substitution below). Execution ends when there are no more words in the

 

list.

select identifier [ in word... ] do list done

Aselect command prints on standard error (®le 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 identi®er 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 identi®er 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-®le (eof) is encountered.

case word in [ [ ( ] pattern [ pattern ] ... ) list ;; ] ... esac

Acase command executes the list associated with the ®rst pattern that matches word. The form of the patterns is identical to that used for ®le 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

®rst

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

Awhile 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 Conditional Expressions below, for a description of expression. Note that [[ and ]] are keywords and require blanks between them and expression.

function identifier { list ;} identifier () { list ;}

De®ne a function referred to by identi®er. The body of the function is the list of commands 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 ®rst 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 ®rst word of each command is replaced by the text of an alias, if an alias for this word has been de®ned. An alias name consists of any number of characters excluding metacharacters, quoting charac- ters, ®le expansion characters, parameter and command substitution characters, and =. The replacement string can contain any valid shell script, including the metacharacters listed above. The ®rst word of each

HP-UX Release 11i: December 2000

− 2 −

Section 1397

k