The read Command

The “read” command can be used to input data from the keyboard, from a file or from a command or set of commands.

The “read” command processes one line at a time.


Input from Where?

While a script is running, a “read” command will, by default, wait for input from <STD_IN> (the keyboard).


read Command Format

The “read” command is followed by one or more arguments.  Each argument is interpreted as a variable in which the data received can be placed.  There will be a one to one matching of input stream arguments to the “read” command arguments.

Example 1

Example 2: Not enough data input

Example 3: More items in the data input than number of variables

Example 4: Quotes do not have special meaning when they are part of the input data stream


read Command Exit Status

read Data in a While Loop

To read in data line-by-line from a file, and halt when all data has been processed, use the format: