in reply to Re: enviorment
in thread Importing environment variables from shell script file to Perl

yep i was tring first this... but as i read more tha bash docs.. export-ed vars are seen only in child processes but my perl script is the parent what I mean :

#!/usr/bin/perl
qx{myenv.sh}
...more code...


see, the env is not seen..why I need shorter solution, 'cause this will be added to many scripts and I dont want to repeat alot of similar code ..

Replies are listed 'Best First'.
Re: Re: Re: enviorment
by iburrell (Chaplain) on Oct 23, 2003 at 19:50 UTC
    If the shell script that sets the variables is simple, then parsing that file is the best way to go. Substituting variable makes things a little harder but isn't too hard to accomplish in Perl. If it is more complicated than this, then it is best to let bash handle the shell scripts. Personally, I would have the config file be simple key=value format. It could be read by bash or perl, but would not be a proper shell script (no #!, no commands).

    You can use bash to run the shell script, print the environment with printenv, and parse the results with Perl

    #!bash # myenvprint.sh source myenv.sh printenv
    #!perl my $myenv = `myenvprint.sh` my %env = parse_env($myenv);