Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import environment settings into my Perl program?

I have a script whose content simply exports a variable in linux.

export LD_LIBRARY_PATH=....

I want to run this script in my Perl script so whoever is running my Perl script will have their LD_LIBRARY_PATH set. Can i just do this in the beginning of my Perl script:

#!/usr/bin/perl -w

system(". /myfolder1/myfolder2/myScript.sh");
like image 892
Saobi Avatar asked Nov 29 '22 12:11

Saobi


1 Answers

#!/bin/sh
. /myfolder1/myfolder2/myScript.sh
exec perl -wxS "$0" "$@"
#!/usr/bin/perl -w
# .. the rest of your script as normal

When you run this, it will first be executed by /bin/sh, which is capable of loading myScript.sh into the local environment. sh then execs Perl, which is told to continue from the following line.

like image 199
ephemient Avatar answered Dec 04 '22 08:12

ephemient