Re: [ILUG] Bash bug or weird rule?

From: Tarlach (tarlach at domain ipeng.com)
Date: Thu 20 Jul 2000 - 15:06:38 IST


> echo "Why will this not work?" | read var
> won't work.
>
> #!/bin/bash
> export VAR="joe"
> VAR=$(
> cat test | while read blah
> do
> echo $blah
> done
> )
> echo $VAR
>
> That's the work around

or just:

echo "Why will this work?" | { read var; echo $var; }

ie group the commands using {} or ()

re mark's original problem, one solution (based on his sample code)
would be something like:

#!/bin/bash
export VAR="blank"
echo ----- $VAR -----
grep VAR t.tmp | awk '{print $2}' | {
        while read blah ; do
                export VAR=$blah
                echo ----- $VAR -----
        done
        echo ----- $VAR ----- # Should $VAR be "variable2" or "blank"
}

or use perl ...

-Tarlach



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:56 GMT