Ash eval wierdness

Christopher Barry christopher.barry at rackwareinc.com
Wed May 25 15:14:49 UTC 2011


On Wed, 2011-05-25 at 14:24 +0000, 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?
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox

would this solve your problem?

grep '^[^[:blank:]]=.*$' file_with_vars_and_other_stuff >/tmp/varfile
. /tmp/varfile


-C




More information about the busybox mailing list