2 .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
5 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
6 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
7 .\" http://www.opengroup.org/bookstore/.
8 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions 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.opengroup.org/unix/online.html.
9 .\" This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
11 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
12 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH READ 1 "Dec 18, 2007"
15 read \- read a line from standard input
19 \fB/usr/bin/read\fR [\fB-r\fR] \fIvar\fR...
25 \fBread\fR \fIname\fR...
31 \fBset\fR \fIvariable\fR= $<
37 \fBread\fR [\fB-prsu\fR [\fIn\fR]] [\fIname\fR ? \fIprompt\fR] [\fIname\fR]...
43 \fBread\fR [\fB-Aprs\fR] [\fB-d\fR \fIdelim\fR] [\fB-n\fR \fInsize\fR] [\fB-N\fR \fInsize\fR] [\fB-t\fR \fItimeout\fR][\fB-u\fR \fIunit\fR] [\fIvname\fR\fB?\fR\fIprompt\fR] [\fIvname\fR... ]
50 The \fBread\fR utility reads a single line from standard input.
53 By default, unless the \fB-r\fR option is specified, backslash (\fB\e\fR) acts
54 as an escape character. If standard input is a terminal device and the invoking
55 shell is interactive, \fBread\fR prompts for a continuation line when:
60 The shell reads an input line ending with a backslash, unless the \fB-r\fR
67 A here-document is not terminated after a \fBNEWLINE\fR character is entered.
71 The line is split into fields as in the shell. The first field is assigned to
72 the first variable \fIvar\fR, the second field to the second variable
73 \fIvar\fR, and so forth. If there are fewer \fIvar\fR operands specified than
74 there are fields, the leftover fields and their intervening separators is
75 assigned to the last \fIvar\fR. If there are fewer fields than \fIvar\fRs, the
76 remaining \fIvar\fRs is set to empty strings.
79 The setting of variables specified by the \fIvar\fR operands affects the
80 current shell execution environment. If it is called in a sub-shell or separate
81 utility execution environment, such as one of the following:
87 find . -exec read ... \e;\fR
94 it does not affect the shell variables in the caller's environment.
97 The standard input must be a text file.
101 One line is read from the standard input and, using the internal field
102 separator, \fBIFS\fR (normally space or tab), to delimit word boundaries, the
103 first word is assigned to the first \fIname\fR, the second word to the second
104 \fIname\fR, and so on, with leftover words assigned to the last \fIname\fR.
105 Lines can be continued using \fB\enewline\fR\&. Characters other than
106 \fBNEWLINE\fR can be quoted by preceding them with a backslash. These
107 backslashes are removed before words are assigned to \fInames\fR, and no
108 interpretation is done on the character that follows the backslash. The return
109 code is \fB0\fR, unless an end-of-file is encountered.
117 set \fIvariable\fR \fB= $<\fR
124 loads one line of standard input as the value for \fIvariable\fR. (See
129 The shell input mechanism. One line is read and is broken up into fields using
130 the characters in \fBIFS\fR as separators. The escape character, \fB(\e)\fR, is
131 used to remove any special meaning for the next character and for line
132 continuation. In raw mode, the \fB-r\fR, the \fB,\fR and the \fB\e\fR character
133 are not treated specially. The first field is assigned to the first \fIname\fR,
134 the second field to the second \fIname\fR, and so on, with leftover fields
135 assigned to the last \fIname\fR. The \fB-p\fR option causes the input line to
136 be taken from the input pipe of a process spawned by the shell using \fB|&\fR.
137 If the \fB-s\fR flag is present, the input is saved as a command in the history
138 file. The flag \fB-u\fR can be used to specify a one digit file descriptor unit
139 \fIn\fR to read from. The file descriptor can be opened with the \fBexec\fR
140 special command. The default value of \fIn\fR is \fB0\fR. If \fIname\fR is
141 omitted, \fBREPLY\fR is used as the default \fIname\fR. The exit status is
142 \fB0\fR unless the input file is not open for reading or an end-of-file is
143 encountered. An end-of-file with the \fB-p\fR option causes cleanup for this
144 process so that another can be spawned. If the first argument contains a
145 \fB?\fR, the remainder of this word is used as a \fIprompt\fR on standard error
146 when the shell is interactive. The exit status is \fB0\fR unless an end-of-file
151 \fBread\fR reads a line from standard input and breaks it into fields using the
152 characters in the value of the \fBIFS\fR variable as separators. The escape
153 character, \fB\e\fR, is used to remove any special meaning for the next
154 character and for line continuation unless the \fB-r\fR option is specified.
157 If there are more variables than fields, the remaining variables are set to
158 empty strings. If there are fewer variables than fields, the leftover fields
159 and their intervening separators are assigned to the last variable. If no
160 \fIvar\fR is specified, the variable \fBREPLY\fR is used.
163 When \fIvar\fR has the binary attribute and \fB-n\fR or \fB-N\fR is specified,
164 the bytes that are read are stored directly into \fIvar\fR.
167 If you specify \fB?\fR\fIprompt\fR after the first \fIvar\fR, \fBread\fR
168 displays a prompt on standard error when standard input is a terminal or pipe.
170 .SS "/usr/bin/read, ksh"
173 The following option is supported by \fB/usr/bin/read\fR and \fBksh\fR:
180 Do not treat a backslash character in any special way. Considers each backslash
181 to be part of the input line.
187 The following options are supported by \fBksh93\fR:
194 Unset \fIvar\fR, and create an indexed array containing each field in the line
195 starting at index \fB0\fR.
201 \fB\fB-d\fR \fIdelim\fR\fR
204 Read until delimiter \fIdelim\fR instead of to the end of line.
210 \fB\fB-n\fR \fInsize\fR\fR
213 Read at most \fInsize\fR bytes. Binary field size is in bytes.
219 \fB\fB-N\fR \fInsize\fR\fR
222 Read exactly \fInsize\fR bytes. Binary field size is in bytes.
231 Read from the current co-process instead of standard input. An end of file
232 causes \fBread\fR to disconnect the co-process so that another can be created.
241 Do not treat \fB\e\fR specially when processing the input line.
250 Save a copy of the input as an entry in the shell history file.
256 \fB\fB-t\fR \fItimeout\fR\fR
259 Specify a \fItimeout\fR in seconds when reading from a terminal or pipe.
265 \fB\fB-u\fR \fIfd\fR\fR
268 Read from file descriptor number \fIfd\fR instead of standard input. The
269 default value is \fB0\fR.
278 When reading from a terminal, display the value of the first variable and use
279 it as a default value.
285 The following operand is supported:
292 The name of an existing or non-existing shell variable.
297 \fBExample 1 \fRUsing the \fBread\fR Command
300 The following example for \fB/usr/bin/read\fR prints a file with the first
301 field of each line moved to the end of the line:
306 example% \fBwhile read -r xx yy
308 printf "%s %s\en" "$yy" "$xx"
314 .SH ENVIRONMENT VARIABLES
317 See \fBenviron\fR(5) for descriptions of the following environment variables
318 that affect the execution of \fBread\fR: \fBLANG\fR, \fBLC_ALL\fR,
319 \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
326 Determines the internal field separators used to delimit fields.
335 Provides the prompt string that an interactive shell writes to standard error
336 when a line ending with a backslash is read and the \fB-r\fR option was not
337 specified, or if a here-document is not terminated after a NEWLINE character is
344 The following exit values are returned:
351 Successful completion.
360 End-of-file was detected or an error occurred.
366 See \fBattributes\fR(5) for descriptions of the following attributes:
367 .SS "/usr/bin/read, csh, ksh, sh"
375 ATTRIBUTE TYPE ATTRIBUTE VALUE
377 Interface Stability Committed
379 Standard See \fBstandards\fR(5).
390 ATTRIBUTE TYPE ATTRIBUTE VALUE
392 Interface Stability Uncommitted
398 \fBcsh\fR(1), \fBksh\fR(1), \fBksh93\fR(1), \fBline\fR(1), \fBset\fR(1),
399 \fBsh\fR(1), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)