如何在Perl的系统()中使用bash语法?
发布时间:2020-12-15 21:11:44 所属栏目:大数据 来源:网络整理
导读:如何在Perl的system()命令中使用bash语法? 我有一个bash特定的命令,例如以下,使用bash的过程替换: diff (ls -l) (ls -al) 我想用Perl来称呼它 system("diff (ls -l) (ls -al)") 但它给我一个错误,因为它使用sh而不是bash来执行命令: sh: -c: line 0: synt
如何在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)'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |