I am essentially trying to assing certain portions of the output of a shell command to mulitple variables, but I don't know how to do that.
For simplicity's sake, assume that the command on the shell, when executes, prints
one two three four
which can be simulated with a
echo "one two three four"
(although the actual comannd is different)
Now, I'd like to assign the second and fourth word of the output (in this case two and four) to the variables w1 and w2.
I thought I could use the read command like so:
echo "one two three four" | awk '{print $2 " " $4}' | read w1 w2
but this doesn't work, probably because the read command is executed in a sub-process.
So, how would I go about to achieve what I am after?