VAR1="FOO"
VAR2="FEE"
VAR3="FUM"
export VAR1
export VAR2
export VAR3
Here is how I sourced it in:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my %envstuff=source_in("source.sh");
print Dumper(\%envstuff);
sub source_in {
my $fname=shift;
my @vars=();
open RIPIT,sprintf("(. $fname ; env) | ",$fname) or die $fname . $
+!;
while(my $line=<RIPIT>){
chomp $line;
my ($key,$val)=split("=",$line);
push @vars,$key,$val;
}
close RIPIT;
return @vars;
}
It ain't pretty but it works. Here is a truncated version of the results:
$VAR1 = {
'VAR1' => 'FOO',
'VAR2' => 'FEE',
'VAR3' => 'FUM',
I'm sure there is more than one way to get this done and
I'll be some of them are quite elegant, but sometimes I
like to just pull a hammer out of the toolbox and whack
nails that stick out.
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
|