Ash eval wierdness
Nigel Hathaway
Nigel.Hathaway at ubiquisys.com
Wed May 25 14:24:59 UTC 2011
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?
More information about the busybox
mailing list