Variables from while/read loops not seen outside of loop
From:
peter . kielbasiewicz
Subject:
Variables from while/read loops not seen outside of loop
Date:
Tue, 13 Jul 2004 14:42:48 +0200
I have various HPUX shell scripts that use the technique below and I do
need to port them to Linux.
In HPUX's Posix shell it is common practice to parse files like:
cat $file | while read line
do
... parse lines and assign results to
variables...
done
... print formatted output of resulting variables...
Unfortunately this does not work at all in bash and I found the reason
under FAQ E4.
All variables set inside the while/read loop are not passed to the parent
shell and thus are unset when I want to print my formatted result
There are two questions here:
1. How does HPUX manage to handle the problem
2. How can I write a solution in bash which gives the desired result
--
best regards
Peter Kielbasiewicz