in reply to UNIX environment setup via perl

Howdy!

#!/usr/bin/perl $ENV{JAVA_HOME}='/path/here'; # set other items in %ENV as appropriate exec '/usr/bin/ksh';

%ENV is your environment. Changes you make in it will be propagated to child processes. When you then exec the new shell, the changed environment carries over.

If you need to process a shell script to set variables, don't try to parse the script. Do something like:

foreach (`. $profile; env`) { chomp; next unless /=/; my ($var, $value) = split(/=/, $_, 2); $ENV{$var} = $value; }

This will execute the script and dump the environment in a straightforward format that you can parse.

yours,
Michael

Replies are listed 'Best First'.
Re: Re: UNIX environment setup via perl
by perlisfun (Sexton) on May 07, 2004 at 22:48 UTC
    Thank you very much for your support. Really apprecaite all of you. I just could not believe perl could not do this easily.
    PerlIsFun

      It isn't a question of Perl being capable or not capable of altering the shell in which it runs. Rather, all shells prevent the scripts and programs they run from altering their environment, to prevent security risks.

      --
      TTTATCGGTCGTTATATAGATGTTTGCA