in reply to sourcing a shell script/.profile and importing into %ENV

It isn't pretty, something along these lines should do the trick:

#!/usr/bin/perl $sourcefile = "/etc/unsafe_profile.sh"; # or whatever chomp(@newenv = qx ( . $sourcefile; env) ); foreach (@newenv) { ($k,$v) = split "=",$_,2; $ENV{$k}=$v; }



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Replies are listed 'Best First'.
Re: Re: sourcing a shell script/.profile and importing into %ENV
by gnu@perl (Pilgrim) on Mar 21, 2003 at 20:06 UTC
    I must apologize to ChemBoy. In my haste with another issue I misread his post. This will work quite well. Thank you.
Re: Re: sourcing a shell script/.profile and importing into %ENV
by zengargoyle (Deacon) on Mar 21, 2003 at 21:12 UTC

    yay++ ChemBoy

    this is also way useful when your *$@*$ sysadmin people only create setup.csh scripts for applications and not the equivalent setup.sh scripts...

Re: Re: sourcing a shell script/.profile and importing into %ENV
by gnu@perl (Pilgrim) on Mar 21, 2003 at 19:54 UTC
    Thanks for your input, but that is sort of the problem I am having. The .profile for the user that I need to source is not just NAME=VALUE pairs, but it has logic in it to set vars under certain circumstances. It even has calls to other programs that it sources, so it has to be run as '. .profile' would do it.

    Yeah, a dumb design, but that's what I have to work with. I didn't do it, but I'm now stuck with it.