[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: read command not reading from pipe. why?

Mark Allums wrote:
On 1/4/2010 1:10 PM, Foss User wrote:
I see that the read command stores input entered only on the console
into the variables. Example:

$ read a
$ echo $a

But when I don't enter input on the console by keyboard, but pipe it
into the standard input of read, I am unable to store the input into
the variable.

$ echo bar | read a
$ echo $a
As others pointed out, the variable a that is read is in another shell. If you want to do something like this, you need to turn it around:

a=$(echo bar)


Reply to: