Sourcing a Shell script into perl

A lot of times we require to source the shell variables or shell script into the perl environment. One way to do this is you add very variable into the perl script something like :

$ENV{”SOME_VAR”} = “SOME_VAL”;

The other best way to do this task is parse the shell file and source all the environment variables in to perl script environment. This way we don’t need to modify your perl script every time the shell script is modified. :)

my ($envar, $enval);
open IN, “. ./3rdParty.env; env |”
or die “Could not run shell: $!\n”;
while ( <IN> ) {
print $_;
chomp;
($envar,$enval) = split /=/,$_,2;
$ENV{$envar} = $enval;
}
close IN;

This is very useful if the shell script is changed very frequently by the users.

One Response to “Sourcing a Shell script into perl”

  1. EARL says:


    CheapTabletsOnline.Com. Canadian Health&Care.Best quality drugs.No prescription online pharmacy.Special Internet Prices. Low price pills. Buy pills online

    Buy:Seroquel.Prozac.Zocor.SleepWell.Buspar.Cozaar.Female Pink Viagra.Wellbutrin SR.Lipitor.Amoxicillin.Ventolin.Advair.Zetia.Lasix.Acomplia.Lipothin.Aricept.Benicar.Female Cialis.Nymphomax….

Leave a Reply