Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

10.0;read, revision 1.0, 88/01/21
read -- Set variables equal to input values.
usage: read {-type {str|int|bool|any|env} var_name... | variable_list}
                [-p[rompt] prompt] [-err[in]]



DESCRIPTION
     The read command reads input values and sets a list of variables to those
     values.  The values from the input line are parsed as separate tokens
     (they must be separated 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.  However, you can 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


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

                    Type            Value

                    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/OS users; please consult
                    the Domain/OS 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:' model class


     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
     "model" and "class", in that order.

     The following section illustrates how the -type option works.  (The
     numbers in parentheses 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> >(2)
     <more> > forty-four                   (3)
     $
     $ lvar
     integer tens = 40
     integer ones = 4
     string number = forty-four
     $


     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.

     Line 2 Shows the error message and prompt when  we enter the non-integer
            value  "four", read cannot assign this value to variable  "ones",
            and  issues  the  error  message  and  prompt.

     Line 3.
            read prompts for the third input value.

     Line 4 The  lvar  command 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 = 1988
     string month = December
     string day = Wednesday
     integer date = 14
     $

     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.

SEE ALSO
     More information is available.  Type TP 1.5i readc For information on
     assigning single-character strings to variables

     readln
          For information on assigning whole-line strings to variables

     export
          For more details about environment variables

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