如何将环境设置导入到我的Perl程序中? [英] How do I import environment settings into my Perl program?

查看:78
本文介绍了如何将环境设置导入到我的Perl程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,其内容只是在Linux中导出一个变量.

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

export LD_LIBRARY_PATH=....

我想在我的Perl脚本中运行此脚本,因此无论谁运行我的Perl脚本,都将设置其LD_LIBRARY_PATH.我可以在Perl脚本的开头执行此操作吗?

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

推荐答案

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

运行此命令时,它将首先由/bin/sh执行,它可以将myScript.sh加载到本地环境中. sh然后是exec s Perl,然后告诉它从下一行继续.

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.

这篇关于如何将环境设置导入到我的Perl程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆