Probably not.
Depending on the script you're trying to replace (really, depending on the
shell it's supposed to run under) you'll find that it is "sourced" in some
way...  Which means that the commands are really executed in the initial
shell, rather than a subshell/child process (which is what usually happens
for shell scripts, and always for anything else, such as a Perl program).
There is no way of manipulating the state of the "parent" process (the shell
you're trying to have an effect on).

What's the script like?  If it's Bourne-shell based (i.e. expected to be run
from a sh, ksh, bash, or similar) it's probably invoked by prepending a dot
and a space ". ".  That means "run the lines in this file as though I had
typed them on my command line".  If it's a csh/tcsh one, it's probably
"source " and then the script name.

Perhaps someone will correct me if I'm leading you astray.  But I'm pretty
sure you can't do what you want to do.

The only way you can do what you want in Perl is to set all those
environment variables, and then fire up the command that you want to run
afterwards from *inside* your Perl.  That way it is a child of your Perl
script, and inherits all the variables you set.
You could presumably fire up a new shell process, and this would do what you
want.
But in most situations I can imagine you're looking at, this isn't an
option.

Hope this helps                         philipp


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 15, 2003 11:36 AM
> To: mongers of perl
> Subject: [Boston.pm] environment variables that "stick"
> 
> 
> I want to write a perl script to 
> replace a Unix shell script which
> does nothing other than create 
> and set environment variables.
> 
> So the perl script might look something like this:
> 
> $ENV{GREGSVAR}='Hello';
> 
> except that when I run the script, the
> assignment doesn't seem to stick, and
> the environment variable GREGSVAR doesn't
> exist after the perl script is finished
> executing.
> 
> looking up environment variables in the
> perl bible and the perl cookbook didn't
> show anything about sticky environment variables.
> 
> can this be done in perl?
> 
> Greg
> _______________________________________________
> Boston-pm mailing list
> [EMAIL PROTECTED]
> http://mail.pm.org/mailman/listinfo/boston-pm
> 
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to