问题描述
我正在尝试从Perl脚本(script.pl)中获取
脚本.
I am trying to source
a script from a Perl script (script.pl).
system ("source /some/generic/script");
请注意,该通用脚本可以是shell,python或任何其他脚本.同样,我无法将此通用脚本中存在的逻辑复制到我的Perl脚本中.我尝试用``, exec
和 qx//
替换 system
.每次出现以下错误:
Please note that this generic script could be a shell, python or any other script. Also, I cannot replicate the logic present inside this generic script into my Perl script. I tried replacing system
with ``, exec
, and qx//
. Each time I got the following error:
我在互联网上遇到了很多论坛,讨论了导致此问题的各种原因.但是他们都没有提供解决方案.有什么方法可以从Perl脚本运行/执行 source
命令?
I came across many forums on the internet, which discussed various reasons for this problem. But none of them provided a solution. Is there any way to run/execute source
command from a Perl script?
推荐答案
在bash等中, source
是一个内置函数,表示读取此文件并在本地对其进行解释(有点像 #include
).
In bash, etc, source
is a builtin that means read this file, and interpret it locally (a little like a #include
).
在这种情况下,这没有任何意义-您要么需要从命令中删除 source
,然后在Shell脚本的开头就有一个shebang(#!
)行告诉系统使用哪个shell执行该脚本,或者您需要明确告诉 system
使用哪个shell,例如
In this context that makes no sense - you either need to remove source
from the command and have a shebang (#!
) line at the start of the shell script that tells the system which shell to use to execute that script, or you need to explicitly tell system
which shell to use, e.g.
system "/bin/sh", "/some/generic/script";
[没有评论在这种情况下是否真正适合使用 system
].
[with no comment about whether it's actually appropriate to use system
in this case].
这篇关于如何运行“源"程序?perl脚本执行命令(Linux)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!