0

I want to read a one-line text and split them, so I decided to use read command. When I try like this,

$ echo 'a b c d' | while read -a VARARR ; do echo ${VARARR[@]}; done
a b c d

All works fine, but It seems like while command is redundant, so I tried

$ echo 'a b c d' | read -a VARARR

But, this does not work. Why?

plhn
  • 5,017
  • 4
  • 47
  • 47

1 Answers1

0

Oh, I found the answer from here.

It says,

because the commands of the pipe run in subshells that cannot modify the parent shell. As a result, the variables of parent shell are not modified

plhn
  • 5,017
  • 4
  • 47
  • 47