read.1 (2010 09)

r
read(1) read(1)
NAME
read - read a line from standard input
SYNOPSIS
read [-r] var ...
DESCRIPTION
read reads a single line from standard input. The line is split into fields as when processed by the shell
(refer to shells in SEE ALSO); the first field is assigned to the first variable var , the second field to the
second variable var , and so forth. If there are more fields than there are specified var operands, the
remaining fields and their intervening separators are assigned to the last var . If there are more var s
than fields, the remaining var s are set to empty strings.
The setting of variables specified by the var operands affect the current shell execution environment.
Standard input to
read can be redirected from a text file.
Since
read affects the current shell execution environment, it is usually provided as a normal shell spe-
cial (built-in) command. Thus, if it is called in a subshell or separate utility execution environment simi-
lar to the following, it does not affect the shell variables in the caller’s environment:
(read foo)
nohup read ...
find . -exec read ... ;
Options
read recognizes the following options:
-r Do not treat a backslash character in any special way. Consider each backslash to be part of
the input line.
Opperands
read recognizes the following operands:
var The name of an existing or nonexisting shell variable.
EXTERNAL INFLUENCES
Environment Variables
IFS determines the internal field separators used to delimit fields.
RETURN VALUE
read exits with one of the following values:
0 Successful completion.
>0 End-of-file was detected or an error occurred.
EXAMPLES
Print a file with the first field of each line moved to the end of the line.
while read -r xx yy
do
printf "%s %s \n" "$yy" "$xx"
done < input_file
SEE ALSO
csh(1), ksh(1), sh(1), sh-posix(1).
STANDARDS CONFORMANCE
read: SVID2, XPG2, XPG3, XPG4, POSIX.2 FIPS
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)