DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

read(1)


read -- read a line from standard input

Synopsis

/usr/bin/read [-r] var ...

Description

This shell script executes the builtin command of the same name as implemented by the /u95/bin/sh( ) shell. See ksh(1) for more information on this shell.

The read command reads a single line from standard input. By default, unless the -r option is specified, backslash (\) acts as an escape character. If standard input is a terminal device and the invoking shell is interactive, read will prompt for a continuation line when:

The line will be split into fields as in the shell. The first field will be assigned to the first variable (var), the second field to the second variable, and so forth. If there are fewer var operands specified than there are fields, the leftover fields and their intervening separators will be assigned to the last var. If there are fewer fields than var operands, the remaining var operands will be set to empty strings. The setting of variables specified by the var operands will affect the current shell execution environment. If it is called in a subshell or separate utility execution environment, such as one of the following:

   (read foo)
   nohup read ...
   find . -exec read ... ;
it will not affect the shell variables in the caller's environment.

Flags


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

Operands


var
The name of an existing or non-existing shell variable.

Input

The standard input must be a text file.

Environment variables

The following environment variables affect the execution of read:

IFS
Determine the internal field separators used to delimit fields. See ksh(1).

LANG
Provide a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

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

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

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

PS2
Provide the prompt string that an interactive shell will write to standard error when a line ending with a backslash is read and the -r option was not specified, or if a here-document is not terminated after a newline character is entered.

Exit codes

An exit code of 0 indicates successful completion; an exit code greater than 0 indicates either that the end-of-file was detected or an error occurred.

Diagnostics

Standard error is used for diagnostic messages and prompts for continued input.

Usage

The results are undefined if an end-of-file is detected following a backslash at the end of a line when -r is not specified.

Examples

The following shell command:
   while read -r xx yy
   do
   printf "%s %s\n" "$yy" "$xx"
   done < input_file
prints a file with the first field of each line moved to the end of the line.

References

ksh(1)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004