Logan Capaldo
7/25/2006 6:32:00 PM
On Jul 25, 2006, at 1:45 PM, ara.t.howard@noaa.gov wrote:
> On Wed, 26 Jul 2006, Logan Capaldo wrote:
>
>>
>> On Jul 25, 2006, at 1:25 PM, Ben Zealley wrote:
>>
>>> The question is this: if I call values.sh from within Ruby (with a
>>> leading period) will I be able to see the updated environment
>>> variables
>>> after it returns, or is this behaviour specific to when one shell
>>> script calls another? (They're ksh scripts, if that information is
>>> helpful)
>>
>> The second one, fortunately or unfortunately as the case may be. .
>> <script>
>> is the source command in ksh, it's equivalent to typing the
>> contents of the
>> shell script in the original file. Theres no why for a child
>> process to
>> affect it's parent's environment. OTOH if values.sh has simple
>> value parts
>> you may be able to parse the script with ruby to pull in the info.
>
> i do something like this
>
> require 'session'
>
> bash = Session::Bash.new
>
> stdout, stderr = bash.execute 'ruby -r yaml -e" y ENV "'
> before = YAML.load stdout
>
> stdout, stderr = bash.execute '. values.sh'
>
> stdout, stderr = bash.execute 'ruby -r yaml -e" y ENV "'
> after = YAML.load stdout
>
> updated = after.to_a - before.to_a
>
> updated.each{|k,v| ENV[k] = v}
>
> which saves you having to parse the file and works even if it's
> horrifically
> complicated...
>
Very neat hack. Only thing I would change would be to do:
...
after = YAML.load stdout
ENV.update(after)
> -a
> --
> suffering increases your inner strength. also, the wishing for
> suffering
> makes the suffering disappear.
> - h.h. the 14th dali lama
>