in reply to how to set environment vars
Consider the following:
#!/usr/bin/perl -w source_it() unless $ENV{foo}; printf "%s = %s\n",$_,$ENV{$_} foreach keys %ENV; exit(0); sub source_it{ exec "echo 'source env.csh ; perl $0' | csh -s"; }
I tested it, it works.
What I'm doing here is looking for a variable that I know should have been set by the sourced in file and if it isn't set I call the sub that execs off a "one-liner" to invoke csh, source in the environment and then re-execute the script. Once that happens the variable I'm looking for is set and I just continue to execute the script as planned. This will work with ksh, bash, sh, with differing command line switches.
This has the additional advantage is that in the event one or more of the values is the result of a scriplet or function buried in the sourced in file it still works. Just parsing the setenv lines won't make that happen.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: how to set environmental vars
by ikegami (Patriarch) on Nov 10, 2005 at 23:59 UTC | |
by blue_cowdawg (Monsignor) on Nov 11, 2005 at 03:33 UTC | |
by ikegami (Patriarch) on Nov 11, 2005 at 03:41 UTC | |
by rsennat (Beadle) on Nov 11, 2005 at 09:54 UTC |