Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

cannot modify LINUX env vars

by ISAI student (Scribe)
on Feb 06, 2011 at 09:28 UTC ( #886490=perlquestion: print w/replies, xml ) Need Help??
ISAI student has asked for the wisdom of the Perl Monks concerning the following question:

Hello all. I am trying to set LINUX environment variables via the %ENV and fail. The chanegs I do to the %ENV do not "stick" at all. I have tried even a simple perl -e and failed. See 1 line two commands LINUX output:
perl -e '$ENV{'pathy'}="kuku"; echo $pathy
I would have expected:
perl -e '$ENV{'pathy'}="kuku"; echo $pathy kuku

Replies are listed 'Best First'.
Re: cannot modify LINUX env vars
by eyepopslikeamosquito (Chancellor) on Feb 06, 2011 at 09:54 UTC
Re: cannot modify LINUX env vars
by Corion (Pope) on Feb 06, 2011 at 09:39 UTC

    That's not how the environment works. Changes are only visible to the current process and its children. You cannot change the "upwards" environment.

    The traditional technique is to output a shell script that the "upper" process then evaluates:

    # In the parent shell do: $(perl -wle 'print "export pathy=kuku') echo $pathy
Re: cannot modify LINUX env vars
by Khen1950fx (Canon) on Feb 06, 2011 at 18:15 UTC
    I tried setenv. I modified the source and used this:
    #!/usr/bin/perl use strict; use warnings; setter( $ENV{'pathy'} = 'kuku' ); system("env"); sub setter { shift; while ( my ( $key, $value ) = splice @_, 0, 2 ) { $ENV{$key} = $value; } return; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://886490]
Approved by Perlbotics
help
Chatterbox?
[LanX]: hey I was told yesterday that "Alma Ata" means father of the apple (ex capital of Kazakhstan) ... so alma is Turkish
[Discipulus]: good point: alms ~charity I made a varronian etymology, sorry, from Alma ~soul
[erix]: alms, aalmoes, almosen from greek eleēmosúnē
[Discipulus]: Almosen is Elemosina in Eatalian
[erix]: yeah, you mediteraaneans are one big family :)
[Discipulus]: greece had to copyrigth etymologies to fill the debt..
[erix]: good no-nonsense american approach to these soft european practices: "Upon entering the Almshouses in Connecticut, patients were whipped up to 10 times"
Discipulus should have..
[erix]: the almshouse generally seems to have become an anglosaxon relic :P
[Discipulus]: just to be sure was not for a free lunch.. sbaaam!

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2017-11-23 20:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (338 votes). Check out past polls.

    Notices?