READ(1)                    POSIX Programmer's Manual                   READ(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       read -- read a line from standard input

SSYYNNOOPPSSIISS
       read [[-r]] _v_a_r...

DDEESSCCRRIIPPTTIIOONN
       The _r_e_a_d utility shall read a single line from standard input.

       By default, unless the --rr option is specified, <backslash> shall act as
       an escape character. An unescaped <backslash> shall preserve the
       literal value of the following character, with the exception of a
       <newline>.  If a <newline> follows the <backslash>, the _r_e_a_d utility
       shall interpret this as line continuation. The <backslash> and
       <newline> shall be removed before splitting the input into fields. All
       other unescaped <backslash> characters shall be removed after splitting
       the input into fields.

       If standard input is a terminal device and the invoking shell is
       interactive, _r_e_a_d shall prompt for a continuation line when it reads an
       input line ending with a <backslash> <newline>, unless the --rr option is
       specified.

       The terminating <newline> (if any) shall be removed from the input and
       the results shall be split into fields as in the shell for the results
       of parameter expansion (see _S_e_c_t_i_o_n _2_._6_._5, _F_i_e_l_d _S_p_l_i_t_t_i_n_g); the first
       field shall be assigned to the first variable _v_a_r, the second field to
       the second variable _v_a_r, and so on. If there are fewer fields than
       there are _v_a_r operands, the remaining _v_a_rs shall be set to empty
       strings. If there are fewer _v_a_rs than fields, the last _v_a_r shall be set
       to a value comprising the following elements:

        *  The field that corresponds to the last _v_a_r in the normal assignment
           sequence described above

        *  The delimiter(s) that follow the field corresponding to the last
           _v_a_r

        *  The remaining fields and their delimiters, with trailing _I_F_S white
           space ignored

       The setting of variables specified by the _v_a_r operands shall affect the
       current shell execution environment; see _S_e_c_t_i_o_n _2_._1_2, _S_h_e_l_l _E_x_e_c_u_t_i_o_n
       _E_n_v_i_r_o_n_m_e_n_t.  If it is called in a subshell or separate utility
       execution environment, such as one of the following:

           ((rreeaadd ffoooo))
           nnoohhuupp rreeaadd ......
           ffiinndd .. --eexxeecc rreeaadd ...... \\;;

       it shall not affect the shell variables in the caller's environment.

OOPPTTIIOONNSS
       The _r_e_a_d utility shall conform to the Base Definitions volume of
       POSIX.1-2008, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s.

       The following option is supported:

       --rr        Do not treat a <backslash> character in any special way.
                 Consider each <backslash> to be part of the input line.

OOPPEERRAANNDDSS
       The following operand shall be supported:

       _v_a_r       The name of an existing or nonexisting shell variable.

SSTTDDIINN
       The standard input shall be a text file.

IINNPPUUTT FFIILLEESS
       None.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _r_e_a_d:

       _I_F_S       Determine the internal field separators used to delimit
                 fields; see _S_e_c_t_i_o_n _2_._5_._3, _S_h_e_l_l _V_a_r_i_a_b_l_e_s.

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2008, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_T_Y_P_E  Determine the locale for the interpretation of sequences of
                 bytes of text data as characters (for example, single-byte as
                 opposed to multi-byte characters in arguments).

       _L_C___M_E_S_S_A_G_E_S
                 Determine the locale that should be used to affect the format
                 and contents of diagnostic messages written to standard
                 error.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

       _P_S_2       Provide the prompt string that an interactive shell shall
                 write to standard error when a line ending with a <backslash>
                 <newline> is read and the --rr option was not specified.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       Not used.

SSTTDDEERRRR
       The standard error shall be used for diagnostic messages and prompts
       for continued input.

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       The following exit values shall be returned:

        0    Successful completion.

       >0    End-of-file was detected or an error occurred.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       Default.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The --rr option is included to enable _r_e_a_d to subsume the purpose of the
       _l_i_n_e utility, which is not included in POSIX.1-2008.

EEXXAAMMPPLLEESS
       The following command:

           wwhhiillee rreeaadd --rr xxxx yyyy
           ddoo
               pprriinnttff ""%%ss %%ss\\nn$$yyyy$$xxxx""
           ddoonnee << _i_n_p_u_t___f_i_l_e

       prints a file with the first field of each line moved to the end of the
       line.

RRAATTIIOONNAALLEE
       The _r_e_a_d utility historically has been a shell built-in. It was
       separated off into its own utility to take advantage of the richer
       description of functionality introduced by this volume of POSIX.1-2008.

       Since _r_e_a_d affects the current shell execution environment, it is
       generally provided as a shell regular built-in. If it is called in a
       subshell or separate utility execution environment, such as one of the
       following:

           ((rreeaadd ffoooo))
           nnoohhuupp rreeaadd ......
           ffiinndd .. --eexxeecc rreeaadd ...... \\;;

       it does not affect the shell variables in the environment of the
       caller.

       Although the standard input is required to be a text file, and
       therefore will always end with a <newline> (unless it is an empty
       file), the processing of continuation lines when the --rr option is not
       used can result in the input not ending with a <newline>.  This occurs
       if the last line of the input file ends with a <backslash> <newline>.
       It is for this reason that ``if any'' is used in ``The terminating
       <newline> (if any) shall be removed from the input'' in the
       description.  It is not a relaxation of the requirement for standard
       input to be a text file.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _C_h_a_p_t_e_r _2, _S_h_e_l_l _C_o_m_m_a_n_d _L_a_n_g_u_a_g_e

       The Base Definitions volume of POSIX.1-2008, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                              READ(1)
