while loop reading from file, var empty (no pipe)
by jt1122 from LinuxQuestions.org on (#6HP3G)
Hi,
Using while to read from a file leaves vars empty outside loop:
Code:echo -e "1 2\nx y\n" >f
while read a b; do echo $a $b; done <f
echo $a $ba & b are read correctly inside the loop but are empty outside it.
When reading from standard input a & b retain their values outside the loop.
why?.
Thanks
Using while to read from a file leaves vars empty outside loop:
Code:echo -e "1 2\nx y\n" >f
while read a b; do echo $a $b; done <f
echo $a $ba & b are read correctly inside the loop but are empty outside it.
When reading from standard input a & b retain their values outside the loop.
why?.
Thanks