in reply to Can you import ENV variables at run time?

Thank you both!

I think this is what I'm going to do:

use Env; ## uid = 0 at this point. ## delete root's env foreach my $key ( keys %ENV ) { delete $ENV{ $key }; } ## set standard PATH, apparently some scripts ## rely on this $ENV{ PATH } = '/bin:/usr/bin:/usr/local/bin:/usr/ucb'; $> = $target_uid; $< = $target_uid; my( $shell, $home ) = ( getpwuid( $> ) ) [ 7, 8 ]; $ENV{ HOME } = $home; my $env_str = qx/exec $shell -c env/; # now parse

Replies are listed 'Best First'.
Re^2: Can you import ENV variables at run time?
by tadman (Prior) on Jul 26, 2001 at 18:47 UTC
    Any reason you couldn't do something like:
    %ENV = ( HOME => $home, PATH => '/bin:/usr/bin:/usr/local/bin:/usr/ucb', );
    Seems a lot simpler than explictly deleting every key of %ENV, and then inserting things one by one.