Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

8.0;read, revision 8.0, 84/03/15
READ -- Set variables equal to input values.
usage:  READ [-P prompt] [-TYPE {string|integer|boolean} variable_name ...]
                                        variable_list


FORMAT

  READ [arguments] variable_list


  The  READ  command  reads  input  values and sets a list of variables to those
  values.  The values from the input line are parsed as  seperate  tokens  (they
  must  be  seperated  by spaces), and each variable in the list is assigned the
  value of a token.

  Use the "-P <prompt>" argument to instruct READ to issue a prompt  other  than
  the  $.  If you do not input values for all the variables names listed as part
  of the READ Command, READ displays the  "<more>"  prompt  to  request  further
  input.

  By default, the type of each variable specified in the READ command depends on
  the  type  of  each  input value.  You can, however, use the -TYPE argument to
  specify the individual type(s) of the the variables.


ARGUMENTS

  -P <prompt>
  (optional)         Specify a particular prompt string  to  request  the  input
                     values.

  -TYPE {string|integer|boolean} variable_name ...
  (optional)          Specify  the  type(s)  of  the  input value(s) that can be
                     assigned to the particular variable_name(s).  If  the  type
                     of  the  input  value does not match the type specified for
                     that variable name, READ issues an error and asks you enter
                     another input  value.    Once  you  specify  a  type  in  a
                     particular  READ  command,  READ  assigns  that type to all
                     subsequent variable  names,  unless  you  change  the  type
                     specification.    Refer to the examples for an illustration
                     of how to use -TYPE.

  variable_list
  (required)         Specify the names of the variables that receive  the  input
                     values.    You must specify variables names either alone or
                     as part of the -TYPE argument.


EXAMPLES

  Consider the following command line in a Shell script:

    READ -P "enter model and class:" mvar cvar

  In this example, READ displays the prompt "enter model and  class:"    in  the
  process  input  window,  and  assigns  the input values to the variables named
  "mvar" and "cvar", in that order.

  The following section illustrates how the -TYPE option works.  (The numbers in
  parentheses are used to refer to the different parts of the example.)

  $ READ -P '> ' -TYPE integer tens ones -TYPE string number  (1)
  > 40 four
  <non-integer 'four'; please reenter> > 4                    (2)
  <more> > forty-four                                         (3)
  $
  $ LVAR                                                      (4)
  integer tens = 40
  integer ones = 4
  string number = forty-four
  $

  In line (1) we define the prompt to be ">  ",  specify  variables  "tens"  and
  "ones"  of  type  "integer",  and  specify variable "number" of type "string".
  This means that the READ command expects its input to be  three  variables  of
  types  integer,  integer,  and  string,  in  that  order.    When we enter the
  non-integer value "four", READ cannot assign this value  to  variable  "ones",
  and  issues  the error message and prompt shown in line (2).  In line (3) READ
  prompts for the third input value.  The LVAR  command,  issued  in  line  (4),
  displays the type, name, and value of the variables.

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