Quote:
Originally Posted by balakodoth
echo "A B C" | read x y z
echo $x $y $z
gives A B C in solaris but when i give same in Linux it gives blank.
does anyone know how to acheive this in Linux ? ( reading from standard input )
|
The problem is that the pipe is being executed in a subshell. 'x', 'y' and 'z' get "A", "B" and "C" assigned. However, after the commands are executed the subshell also exits and the assigned values are lost.
If you want to keep them you can do something like this:
Code:
$ read x y z < <(echo "D E F")
$ echo $x
D
$ echo $y
E
$ echo $z
F
$ echo $x $y $z
D E F
$