[TriLUG] possible awk/grep question

Joseph Mack NA3T jmack at wm7d.net
Tue Jan 22 08:24:12 EST 2008


On Thu, 17 Jan 2008, Paul McLanahan wrote:

> I have, however, gotten the following syntax to work. This syntax is only
> superior to the pipe method mentioned above when you need to maintain
> context inside the loop. When you use the pipe, the loop executes in a
> sub-shell, and therefore all variables created or modified inside the loop
> are not available after the loop. I had to use this because I was collecting
> information in a variable inside a loop which I wanted to use later in the
> script, and when I tried that using the "command | while read line; do"
> syntax, I lost my context.

I tried declare -x to export the variable, but it didn't 
work.


while read line
do

      declare -x first_variable
      first variable=`echo $line | awk '{print $1}'`
      export $first_variable
     collection="$collection $line"
done < <(command)
> # do stuff with $collection ...

env
echo $first_variable

nothing is printed.

is this what declare -x is supposed to handle? (I thought 
you weren't allowed to export variables back to the 
parent; it's a security hole.)

Thanks Joe
--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!



More information about the TriLUG mailing list