Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

READC

READLN

EXPORT

9.0;read, revision 9.0, 85/03/26
READ -- Set variables equal to input values.
usage:  READ {-TYPE {STR|INT|BOOL|ANY|ENV} var_name... | variable_list}
                                        [-P[ROMPT] prompt] [-ERR[IN]]


FORMAT

  READ [options] {-TYPE type var_name ... | 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.   If  you  do
  not  input  values  for  all  the  variables  names listed as part of the READ
  command, READ displays a "<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

  variable_list
  (optional)         Specify the names of the variables that receive  the  input
                     values.

                     Default if omitted:  must specify -TYPE (below).


OPTIONS

  -TYPE type var_name...
                     Specify the type of the input value(s) that can be assigned
                     to  the  particular  variable  name(s).   Multiple variable
                     names are permitted, separated by blanks.  Once you specify
                     a type in a particular READ command, READ assigns that type
                     to all subsequent variable names, until you change the type
                     specification.  Valid types are

                         STR[ING]         character strings
                         INT[EGER]        integer numbers
                         BOOL[EAN]        Boolean values
                         ENV[IRONMENT]    environment variables
                         ANY              any type (the default)

                     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.   Use -TYPE ANY to
                     restore the Shell to its default state.  In this  case,  it
                     determines the proper variable type automatically.

                     Specifying -TYPE ENV var_name causes the variable to become
                     an environment variable.    Environment  variables  are  of
                     primary  concern  to  DOMAIN/IX  users;  please consult the
                     DOMAIN/IX documentation for details about their usage.

  -P[ROMPT] prompt
                     Specify  a  particular  prompt  string to request the input
                     values.  Enclose the string in single quotes if it contains
                     literal blanks.

  -ERR[IN]            Read  input  from  error  input instead of standard input.
                     This option is useful  for  reading  user  input  from  the
                     Shell's  input pad (where error input is normally directed)
                     when the READ command  appears  inside  a  pipeline,  since
                     standard input in that case is connected to the pipe.


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.

  Here is a final example.

      $ date | chpat ',' '' | (read day month date year; readln time)
      $ lvar
      string time =   12:40:42 pm (EST)
      integer year = 1985
      string month = January
      string day = Wednesday
      integer date = 2
      $

  In  this  example,  the  output from the DATE command is piped to CHPAT, which
  removes the commas and then sends its output to  READ  and  READLN  where  the
  proper variable assignments are made.


RELATED TOPICS

  More information is available.  Type:

  - HELP READC
   for information on assigning single-character strings to variables.

  - HELP READLN
   for information on assigning whole-line strings to variables.

  - HELP EXPORT
   for more details about environment variables.

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