问题描述
我有像我的名字$
变量的Perl脚本。我们可以设置$ name的内容作为一个环境变量,我们可以导入和其他文件中使用?
I have a Perl script which has a variable like my $name
. Can we set the contents of $name as an environment variable which we can import and use in other files?
我试着像 $ ENV {NAME} =名称
,但是这是行不通的。
I tried like $ENV{NAME}=name
, but this is not working.
推荐答案
如果要影响你的进程或子进程的环境中,只要用%ENV
哈希值:
If you want to affect the environment of your process or your child processes, just use the %ENV
hash:
$ENV{CVSROOT}='<cvs>';
如果您要影响你的父进程的环境下,你不能。至少在没有父进程的合作。标准的过程是发出一个shell脚本,并有父进程执行该shell脚本:
If you want to affect the environment of your parent process, you can't. At least not without cooperation of the parent process. The standard process is to emit a shell script and have the parent process execute that shell script:
#!/usr/bin/perl -w
print 'export CVSROOT=<cvs>';
......,并呼吁从shell(脚本)脚本:
... and call that script from the shell (script) as:
eval `myscript.pl`
这篇关于我们可以设置在Perl脚本作为一个环境变量使用的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!