如何在Perl的system()命令中使用bash语法?
我有一个bash特定的命令,例如以下,使用bash的过程替换:
diff <(ls -l) <(ls -al)
我想用Perl来称呼它
system("diff <(ls -l) <(ls -al)")
但它给我一个错误,因为它使用sh而不是bash来执行命令:
sh: -c: line 0: Syntax error near unexpected token `('
sh: -c: line 0: `sort <(ls)'
告诉Perl直接
调用bash.使用
system()
的列表变体来减少引用的复杂性:
my @args = ( "bash","-c","diff <(ls -l) <(ls -al)" );
system(@args);
你甚至可以定义一个子程序,如果你打算这么做的经常:
sub system_bash {
my @args = ( "bash",shift );
system(@args);
}
system_bash('echo $SHELL');
system_bash('diff <(ls -l) <(ls -al)');