[clug] Amusing little /bin/sh question..

Andrew Janke a.janke at gmail.com
Wed May 23 07:27:38 GMT 2007


> > I forgot one (rather) crucial bit...  I want to find out what somevar
> > is but I dont want to run the script itself (thus the set -n
> > fiddling).
>
> Well... in that case, I think you'll need to decide on what assumptions
> you can make about a.sh's behaviour - otherwise you're going to hit
> computability issues.

Aye.. :(

> IF you are willing to assume that the variable is simply set with
> somevar="foo", running a regex over the file to get the value is an
> easy-enough way to get the value.

For now I am running with this evil bit of line-noise that is sure to
cause me grief in years to come.

   sstage=`grep -v \# a.sh | grep somevar | head -1 | cut -f2 -d\= |
sed -e 's/"//g'`

> Is it possible to rearrange the files in question? In that case you can
> split off something akin to a "config file".  Put the assignment in the
> config file, source the config file from both a.sh and b.sh.

It is, but will make things infinitely more ugly that the above in may
other places, essentially I was looking for a way to source a.sh in
such a way that all variable assignments are done but no running
commands.

I am the only one who will likely ever be editing a.sh (and in this
case there are about 20 a.sh scripts that are all written in the same
style that I want to get he value of somevar from so that would mean
20 config files and 20 scripts.. :( )

Thanks all anyhow.


a


More information about the linux mailing list