Ash eval wierdness

Chuck Meade chuckmeade at mindspring.com
Wed May 25 14:37:29 UTC 2011


On 05/25/2011 10:24 AM, Nigel Hathaway wrote:
> I'm trying to import a set of variables from a file containing assignments of the form "a=b", one on each line. I am finding that the variable assignments are being lost.
> 
> Here is a simplified version of my script which illustrates the problem:
> 
> echo "myvar=my value" | while read opt; do 
>     if echo "$opt" | grep -q '='; then
>         var=`echo "$opt" | /bin/sed "s/=.*//"`
>         val=`echo "$opt" | /bin/sed "s/[^=]*=//"`
>         eval $var=\'$val\'
>         echo "(1)" $var=\'$val\'
>         echo "(2) myvar=$myvar"
>     fi
> done
> echo "(3) myvar=$myvar"
> 
> Which yields this:
> 
> (1) myvar='my value'
> (2) myvar=my value
> (3) myvar=
> 
> I am using Busybox v1.18.4
> 
> Any idea what is going on?

Hi Nigel,

You will get the same results if you run that logic through bash.
The problem is that your eval logic only has effect until the loop
(everything after the pipe '|') ends.

Run it in bash and you will see the same thing.

Chuck


More information about the busybox mailing list