[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

How does a pipe works?



Hello,
The problem pertains to simple shell script. I am unable to analyze the
follwing ,  can any one on the list explain me :

$echo HELLO | read var_name    # here I pipe the o/p of echo command to
a variable
$echo $var_name                       # here I check that "HELLO" is
stored in the user defined variable
HELLO
$

The above comand works fine. Now consider this

$ read var_name  |  echo HELLO
HELLO
<here some i/p has to be fed by the user>
$echo $var_name     # I try to see what the variable has been read into
<blank line displayed>
$

Though the standard i/p waits for some i/p from user, the variable is
not assigned the value.
Why this is so?

--TIA
RK