Article 6HP3G while loop reading from file, var empty (no pipe)

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
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments