Ash eval wierdness

Harald Becker ralda at gmx.de
Wed May 25 18:00:13 UTC 2011


 Hallo Bob!

>   eval $(sed -n -e 's/=\(.*\)/="\1"/p' < file)

Why do you redirect the input file here?

eval $( sed -n -e 's/=\(.*\)/="\1"/p' file )

... shall do the job.

In addition it is possible to strip of spaces around = (if required):

eval $( sed -n -e 's/ *= *\(.*\)/="\1"/p' file )

With some more tricky sed scripts you can even suppress comments in the
file, select only specific variables for usage and more, e.g.

eval $( sed -n \
            -e '/^$/d' \
            -e '/^#/d' \
            -e 's/^\([a-z_]+\) *= *\(.*\)/\1="\2"/' \
            -e '/^abc=/p' \
            -e '/^xyz=/p' \
        file )

... just to give some examples.

--
Harald


More information about the busybox mailing list