Re: How to set environment variable



can't you set the environmental variables for the parent shell
by running a script as a . or here file?



-----Original Message-----
From: Jeff Pang <rwwebs@xxxxxxxxx>
Sent: Sep 27, 2007 10:02 AM
To: vikram vikram vikram <vicky_brsh@xxxxxxxxxxxxxx>
Cc: beginners@xxxxxxxx
Subject: Re: How to set environment variable

27 Sep 2007 14:47:42 -0000, vikram vikram vikram <vicky_brsh@xxxxxxxxxxxxxx>:

Hi All,

I am new to perl. I am using "Active Perl-5.8.8"

I want to set environment variable in a perl script

Ex - #!/usr/bin/perl
$ENV{HAI} = "hai";


and want to display the contents of the environment variable in the command line after executing the script.

But it is not displaying the contents if i give
echo $HAI


Hi,

When you start to run a perl program,a separate process is
started,which is different from your current shell process.So you
can't set the environment variables from another process to the
current shell process.

you can do a test,
$ perl -MData::Dumper -e '$ENV{TEST}=1;print Dumper \%ENV'
this would print what you want.
but,
$ echo $TEST
will get nothing.

--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/



.



Relevant Pages

  • Re: Unexpected retrieved value in Environment Varaibles
    ... dirty little hardware inventory script that I call from the main login ... Pentium4 CPU 3.00GHz Winnipeg ... WPGAGEDKAREN-H2 Microsoft Windows XP Professional Intel ... I tend to obtain my environmental variables like so: ...
    (microsoft.public.scripting.vbscript)
  • Re: system ("source ...");
    ... I want to set some environmental variables in order to be visible ... > to the script children programs. ... I consider putting them in a different perl script using %ENV. ... one Perl file in another, you want either do, require, or use, again ...
    (perl.beginners)
  • Defining environment variables and cgi scripts
    ... I have a cgi script I want apache to execute for me. ... The problem I'm having is I don't know how to include editional environmental variables that the script requires. ... How do I add a variable called PAYMENTIC_HOME to the list of environment variables that perl knows about when executing a script under apache? ...
    (Debian-User)
  • Re: Small doubt in perl
    ... In the "sample.sh" i have set some environmental variables, ... You need to locate the shell used for sample.sh, ... which makes the shell run the script in the same process. ... which will save a fork. ...
    (comp.lang.perl.misc)
  • Re: system ("source ...");
    ... I want to set some environmental variables in order to be visible ... to the script children programs. ... I consider putting them in a different perl script using %ENV. ...
    (perl.beginners)