gpt4 book ai didi

perl 反引号 : use bash instead of sh

转载 作者:行者123 更新时间:2023-11-29 08:58:27 24 4
gpt4 key购买 nike

我注意到当我在 perl 中使用反引号时,命令是使用 sh 而不是 bash 执行的,这给我带来了一些问题。

我怎样才能改变这种行为,以便 perl 将使用 bash?

附言。我尝试运行的命令是:

paste filename <(cut -d \" \" -f 2 filename2 | grep -v mean) >> filename3

最佳答案

“系统外壳”通常不是可变的。参见 perldoc -f exec :

If there is more than one argument in LIST, or if LIST is an array with more than one value, calls execvp(3) with the arguments in LIST. If there is only one scalar argument or an array with one element in it, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is "/bin/sh -c" on Unix platforms, but varies on other platforms).

如果您确实需要 bash 来执行特定任务,请考虑显式调用它:

my $result = `/usr/bin/bash command arguments`;

甚至:

open my $bash_handle, '| /usr/bin/bash' or die "Cannot open bash: $!";
print $bash_handle 'command arguments';

您还可以将 bash 命令放入 .sh 文件并直接调用它:

my $result = `/usr/bin/bash script.pl`;

关于perl 反引号 : use bash instead of sh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3374082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com