Command read


Name

read Reads one line from stdin and assigns to variables

Synopsis

read var1 [var2 ... varn]


Reads one line from stdin, splits the line into fields using any of the charactors in the IFS variable (default space,tab),
and assigns the values to the specified variables.

Example:
read a b <<EOF
string1 string2
EOF
echo $a $b

Result
string1 string2


Commands
CategoryCommands

Comments [Hide comments]
Comment by DavePawson
2010-05-02 03:05:07
Note, the <<EOF isn't necessary in a script. It is here simply to indicate
that the input is terminated.

read a b

Is needed, no more.
Comment by DavidLee
2010-05-04 10:15:03
In the first example, <<EOF IS needed because thi is a "here document" where the input to the read command is taken from the script body, not the input of the script.

Without the <<EOF then "read a b" will read from stdin.

But I agree it could be clarified that this is intentionally both an example of read and of here documents in one.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki