How do I import environment settings into my Perl program?

environment, linux, perl

Solution

#!/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 `exec`s Perl, which is told to continue from the following line.

Problem

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"); ```

Original source

Related problems