read - read line of input from standard input


read [-prs] [-u[n]] parameter ...


The read(1) utility reads a line of input from standard input, separates the line into fields using the shell's IFS parameter, and assigns each field to the specified parameters. If there are more parameters than fields, the extra parameters are set to null, or alternatively, if there are more fields than parameters, the last parameter is assigned the remaining fields (inclusive of any separating spaces). If no parameters are specified, the REPLY parameter is used.

In an interactive shell, if the input line ends in a backslash, and the -r option was not used, the backslash and newline are stripped, and more input is read. If no input is read, read(1) exits with a non-zero status.

To specify a prompt that is printed to standard error before any input is read, append a question mark and the prompt to the first parameter (for example, read napple?'number of apples: ').

The read(1) command takes the following options:

Read from the current co-process.
Do not treat the backslash (\) as a special character.
Save input to the history file.
-u n
Read from file descriptor n. If no descriptor is given, file descriptor 0 is used.