I want to import environment variables set in my linux user shell file into my perl script ? And i don't want to parse for key=value pairs. How can this be done ?
Import linux environment variable from shell file
179 Views Asked by Dexter At
4
There are 4 best solutions below
1

Assuming you want to get them from your current shell rather than an arbitrary file, you actually have access to all your environment variables, such as with:
pax> perl -e 'print $ENV{"HOME"}."\n"'
/home/pax
or, if you want to enumerate them all (in sorted order, for example):
foreach $key (sort keys %ENV) {
print "[$key] -> [$ENV{$key}]\n";
}
0

This can now be done with the Env::Modify
module.
use Env::Modify 'source';
source("$ENV{HOME}/.my_user_shell_file");
0

Look at the solution here: http://darkdiary.ru/users/TLoD_Snake/3233201/comment/
Perl executes your shell command file and reexecutes itself if it figures out that shell command was not executed before.
I've found this solution from TLoD_Snake here on StackOverflow, but I can not find the exact question, so I just point you to his blog.
You can use the
Env
module.$ENV{Variablename}