Name
read
Synopsis
read [options] [variable1[variable2…]]
Read one line of standard input and assign each word to the corresponding variable, with all leftover words assigned to the last variable. If only one variable is specified, the entire line is assigned to that variable. See the Examples here and under case. The return status is 0 unless EOF is reached. If no variables are given, input is stored in the REPLY variable.
Options
-aarrayRead into indexed array array.
-ddelimRead up to first occurrence of delim, instead of newline.
-eUse the readline library if reading from a terminal.
-ncountRead at most count bytes.
-ppromptPrint prompt before reading input.
-rRaw mode; ignore \ as a line-continuation character.
-sRead silently; characters are not echoed.
-ttimeoutWhen reading from a terminal or pipe, if no data is entered after timeout seconds, return 1. This prevents an application from hanging forever, waiting for user input.
-u[n]Read input from file descriptor n (default is 0).
Examples
Read three variables:
$read first last addressSarah Caldwell 123 Main Street$echo "$last, $first\n$address"Caldwell, Sarah 123 Main Street
Prompt yourself to enter two temperatures:
$read -p "High low: " n1 n2High low:65 33
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access