10.0;select, revision 1.0, 88/01/21
select -- Execute a select statement.
usage:
select arg [oneof|allof]
case arg [to arg]
[command...]
[case...
command...]
[otherwise
command...]
endselect
DESCRIPTION
select allows you to build a control structure that executes commands
according to the results of one or more Boolean tests. The shell uses
each case clause to perform a separate Boolean test on the initial select
argument. If the case argument is equal to the select argument, the
result of the test is true and the command(s) within the case clause
execute.
You may test multiple cases simultaneously. If you place several case
clauses on the same line (or specify line continuation with RETURN, the
cases are logically or'd and return true if any one of the cases is true.
(See example below.)
The (optional) to clause allows you to specify an integer or string range
for testing. For example, you might specify case 0 to 9 to test for any
single digit, or case a to z to test for a lowercase letter.
The (optional) otherwise clause executes if and only if none of the case
clauses returns true (regardless of whether the selection mode was oneof
or allof).
ARGUMENTS
arg (required) Any valid token, defined integer or string variable, or
expression. select compares the first arg with each of
the case arg's to determine which command(s) to execute.
mode (optional)
Specify selection mode. Valid modes are oneof and allof.
If you specify oneof (the default), select executes only
the first case statement that returns a true value. If
you specify allof, select executes all case statements
that return true.
Default if omitted: use oneof
command... (optional)
Specify the command to be executed when the case test
returns true. This may be a shell command, a shell
script, a variable assignment, or any other valid shell
operation. Multiple commands are permitted; separate them
with semicolons or newline characters.
Default if omitted: no command executed for this case clause
EXAMPLES
select ^a allof
case 1 case 2 case 3
args "This will print if ^a = 1 or ^a = 2 or ^a = 3"
case 1 @
case 2 @
case 3
args "This is the same test as the previous one, since the"
args "carriage returns are escaped."
case 4 # This is a case without a body to execute.
case 5 to 10
args "This will print if ^a is in the range 5-10."
case 6
args "This will also print if ^a = 6, since allof is"
args "specified."
otherwise
args "This will print if ^a is not between 1 and 10."
endselect