MPE/iX Shell and Utilities Reference Manual, Vol 2
sh(1) MPE/iX Shell and Utilities sh(1)
for variable [in word ...]
do command
done
The for statement sets variable to each word argument in turn, and executes the set
of commands once for each setting of variable. If you omit the in word part, sh sets
variable to each positional parameter. You may divert the flow of control within the
loop with the break(1) or continue(1) statements.
function variable {
command
}
variable() {
command
}
Either of these forms defines a function named variable, the body of which con-
sists of the sequence of commands. You invoke a function just like any other com-
mand; when you actually call the function, sh saves the current positional parame-
ters. The function’s command line arguments then replaces these parameters until
the function finishes. If the option flag –K is set, sh also saves the current ERR and
EXIT traps and any flags manipulated with the set command; these are restored
when the function finishes. The function terminates either by falling off the end of
the code of the function body, or by reaching a return(1) statement. If the function
uses typeset to declare any variables in the function body, the variables are local
to the function.
if command
then command
[elif command
then command] ...
[else command]
fi
In the if statement, if the first (leftmost) command succeeds (returns a zero exit sta-
tus), sh executes the command following then; otherwise, sh executes the com-
mand (if any) following the elif (which is short for "else if"); if that succeeds, sh
executes the command following the next then. If none of these cases hold, sh exe-
cutes the command following the else (if any).
select variable [in word ...]
do commands
done
The select statement can handle menu-like interactions with the user. Its syntax is
like the for statement. Each word is printed on the standard error file, one per line,
with an accompanying number. If you omit the "in word..." part, sh uses the
1-524 Commands and Utilities