1READ(1P)                   POSIX Programmer's Manual                  READ(1P)
2
3
4

PROLOG

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

NAME

12       read - read a line from standard input
13

SYNOPSIS

15       read [-r] var...
16

DESCRIPTION

18       The read utility shall read a single line from standard input.
19
20       By default, unless the -r option is specified, backslash ( '\' )  shall
21       act  as  an  escape  character, as described in Escape Character (Back‐
22       slash) . If standard input is a terminal device and the invoking  shell
23       is interactive, read shall prompt for a continuation line when:
24
25        * The shell reads an input line ending with a backslash, unless the -r
26          option is specified.
27
28        * A here-document is not terminated after a <newline> is entered.
29
30       The line shall be split into fields as in the shell (see  Field  Split‐
31       ting  );  the  first field shall be assigned to the first variable var,
32       the second field to the second variable var, and so on.  If  there  are
33       fewer var operands specified than there are fields, the leftover fields
34       and their intervening separators shall be assigned to the last var.  If
35       there  are  fewer  fields than vars, the remaining vars shall be set to
36       empty strings.
37
38       The setting of variables specified by the var operands shall affect the
39       current  shell execution environment; see Shell Execution Environment .
40       If it is called in a subshell or separate  utility  execution  environ‐
41       ment, such as one of the following:
42
43
44              (read foo)
45              nohup read ...
46              find . -exec read ... \;
47
48       it shall not affect the shell variables in the caller's environment.
49

OPTIONS

51       The  read  utility  shall  conform  to  the  Base Definitions volume of
52       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
53
54       The following option is supported:
55
56       -r     Do not treat a backslash character in any special way.  Consider
57              each backslash to be part of the input line.
58
59

OPERANDS

61       The following operand shall be supported:
62
63       var    The name of an existing or nonexisting shell variable.
64
65

STDIN

67       The standard input shall be a text file.
68

INPUT FILES

70       None.
71

ENVIRONMENT VARIABLES

73       The following environment variables shall affect the execution of read:
74
75       IFS    Determine  the internal field separators used to delimit fields;
76              see Shell Variables .
77
78       LANG   Provide a default value for the  internationalization  variables
79              that  are  unset  or  null.  (See the Base Definitions volume of
80              IEEE Std 1003.1-2001, Section  8.2,  Internationalization  Vari‐
81              ables  for the precedence of internationalization variables used
82              to determine the values of locale categories.)
83
84       LC_ALL If set to a non-empty string value, override the values  of  all
85              the other internationalization variables.
86
87       LC_CTYPE
88              Determine  the  locale  for  the  interpretation of sequences of
89              bytes of text data as characters (for  example,  single-byte  as
90              opposed to multi-byte characters in arguments).
91
92       LC_MESSAGES
93              Determine  the  locale  that should be used to affect the format
94              and contents of diagnostic messages written to standard error.
95
96       NLSPATH
97              Determine the location of message catalogs for the processing of
98              LC_MESSAGES .
99
100       PS2    Provide  the prompt string that an interactive shell shall write
101              to standard error when a line ending with a  backslash  is  read
102              and  the  -r  option was not specified, or if a here-document is
103              not terminated after a <newline> is entered.
104
105

ASYNCHRONOUS EVENTS

107       Default.
108

STDOUT

110       Not used.
111

STDERR

113       The standard error shall be used for diagnostic  messages  and  prompts
114       for continued input.
115

OUTPUT FILES

117       None.
118

EXTENDED DESCRIPTION

120       None.
121

EXIT STATUS

123       The following exit values shall be returned:
124
125        0     Successful completion.
126
127       >0     End-of-file was detected or an error occurred.
128
129

CONSEQUENCES OF ERRORS

131       Default.
132
133       The following sections are informative.
134

APPLICATION USAGE

136       The  -r option is included to enable read to subsume the purpose of the
137       line utility, which is not included in IEEE Std 1003.1-2001.
138
139       The results are undefined if an end-of-file  is  detected  following  a
140       backslash at the end of a line when -r is not specified.
141

EXAMPLES

143       The following command:
144
145
146              while read -r xx yy
147              do
148                  printf "%s %s\n" "$yy" "$xx"
149              done < input_file
150
151       prints a file with the first field of each line moved to the end of the
152       line.
153

RATIONALE

155       The read utility historically has been a shell built-in. It  was  sepa‐
156       rated off into its own utility to take advantage of the richer descrip‐
157       tion    of    functionality    introduced    by    this    volume    of
158       IEEE Std 1003.1-2001.
159
160       Since  read affects the current shell execution environment, it is gen‐
161       erally provided as a shell regular built-in. If it is called in a  sub‐
162       shell  or  separate  utility  execution environment, such as one of the
163       following:
164
165
166              (read foo)
167              nohup read ...
168              find . -exec read ... \;
169
170       it does not affect the shell variables in the environment of the  call‐
171       er.
172

FUTURE DIRECTIONS

174       None.
175

SEE ALSO

177       Shell Command Language
178
180       Portions  of  this text are reprinted and reproduced in electronic form
181       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
182       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
183       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
184       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
185       event of any discrepancy between this version and the original IEEE and
186       The  Open Group Standard, the original IEEE and The Open Group Standard
187       is the referee document. The original Standard can be  obtained  online
188       at http://www.opengroup.org/unix/online.html .
189
190
191
192IEEE/The Open Group                  2003                             READ(1P)
Impressum