This should be good for getting all environment variables.
for(`program; env`){ if( /^([^=]+)=(.*)$/ ) { $hash{$1} = $2; } }
If you want to start from scratch, this might work better.
for(`env -i bash -c "program; env"`){ next if /\(\)/; if( /^([^=]+)=(.*)$/ ) { $hash{$1} = $2; } }
env -i forces his subcommand to start from scratch.
It calls bash with the -c argument and commands to run. We must do this, because otherwise the second env will not get the environment variables from the program.
source share