[clug] Amusing little /bin/sh question..
Kim Holburn
kim.holburn at gmail.com
Wed May 23 20:17:36 GMT 2007
A small change to a.sh:
--------------------
#! /bin/sh
set -e
set -o nounset
somevar="a-value"
if [ "$1" = "--somevar" ]; then
exit
fi
<lots of other things with $somevar>
----------------
in another script:
. a.sh --somevar
echo $somevar
On 2007/May/23, at 8:52 AM, Andrew Janke wrote:
> 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
> --
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux
--
Kim Holburn
IT Network & Security Consultant
Ph: +39 06 855 4294 M: +39 3494957443
mailto:kim at holburn.net aim://kimholburn
skype://kholburn - PGP Public Key on request
Democracy imposed from without is the severest form of tyranny.
-- Lloyd Biggle, Jr. Analog, Apr 1961
More information about the linux
mailing list