Read

From LQWiki
Jump to navigation Jump to search

read is a bash command. It reads a standard line of input and assigns each word to the corresponding variable. If the number of words exceeds the number of variables, all the last words are assigned to the last variable.

Example:

$ read firstname lastname address
Joseph Bloggs 127 Bloggity Avenue
$ echo "$firstname $lastname\n$address"
Joseph Bloggs
127 Bloggity Avenue

Options

-t set a timeout for the answer
-d char Stop reading at char instead of at newline
-s will suppress echo, useful for passwords

For more options, see the man page.