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: How do implement this wildcard?
    ... The "x" makes the script robust so that it does not fail in the line below ... for environmental variables, ... The script determines whether or not the parameter is a UNC, ... significantly more difficult to determine using batch alone. ...
    (microsoft.public.windows.server.scripting)
  • 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)
  • Re: creating Environment variable during logon script
    ... script, I can get it to create the variable during execution however, ... Here are a few options to create non-transient environmental variables: ... For Each str In oWsShell.Environment ...
    (microsoft.public.scripting.vbscript)
  • Re: How do implement this wildcard?
    ... The "x" makes the script robust so that it does not fail in the line below ... for environmental variables, ... Every process, whether it is a Command Processor or some other executable, ... You need to execute a ...
    (microsoft.public.windows.server.scripting)