Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ select — Apollo

Media Vault

Software Library

Restoration Projects

Artifacts Sought

9.0;select, revision 9.0, 85/03/27
SELECT -- Execute a SELECT statement.
usage:
SELECT arg [ONEOF|ALLOF]
    CASE arg [TO arg]
         [command...]
    [CASE...
         command...]
    [OTHERWISE
         command...]
ENDSELECT


FORMAT

      SELECT arg [mode]
          CASE arg [TO arg]
               [command...]
          [CASE...
               command...]
          [OTHERWISE
               command...]
      ENDSELECT


  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

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026