[clug] Amusing little /bin/sh question..
Andrew Janke
a.janke at gmail.com
Wed May 23 06:52:38 GMT 2007
Hi all,
Just a quick one that has be somewhat bemused..
If I have one shell script (a.sh) as such:
----
#! /bin/sh
set -e
set -o nounset
somevar="a-value"
<lots of other things with $somevar>
----
How can I get what the value of somevar in another script, for example
I can do this on the C/L:
mavis:dir$ set -n && a.sh && echo $somevar
Things will sort of work but the question is how to do this within
another shell script as such (b.sh)
---
#! /bin/sh
set -e
set -o nounset
thevalueIwant=`something magic with a.sh`
---
Of course I could resort to dirty tricks such as this:
thevalueIwant=`grep somevar a.sh | head -1 | cut -f2 -d\=`
But then I am relying on myself not writing a comment about somevar
and other things.. Of course I could do this....
thevalueIwant=`grep -v \# a.sh | grep somevar | head -1 | cut -f2 -d\=`
but now we are getting really ugly.
Just wanted to know if anyone knows a "nice" way to do this.
ta
a
PS: answers of converting it to perl/python/ruby/etc are not
considered answers! :)
--
Andrew Janke (a.janke at gmail.com || http://a.janke.googlepages.com/)
Canberra->Australia +61 (402) 700 883
More information about the linux
mailing list