【发布时间】:2014-02-09 02:48:21
【问题描述】:
my @cmd=`ls {??_in,??}.pl`;
print @cmd;
如果运行那个程序会报错
`ls: cannot access {??_in,??}.pl: No such file or directory`
现在它已经在终端上运行了
cmd>ls {??,??_in}.pl
cmd>aa_in.pl aa.pl ls.pl
所以它在命令行中产生输出,为什么在 perl 中不考虑那个花括号。
【问题讨论】:
-
花括号由 shell 解释,而不是由
ls命令解释。您可以尝试通过 shell 调用命令,例如bash -c 'ls {??,??_in}.pl' -
perl 只需
execs 您在没有 shell 的情况下给出的命令。另一方面,执行 globbing 的是 shell。 -
perl 是否使用与您相同的 shell?也许是 Bash 与 csh?
-
@Bill Ruppert,Perl 始终使用
/bin/sh,Windows 除外 -
@devnull:shell 确实 在此处输入图片(隐式通过
/bin/sh -c),因为命令字符串包含(未引用的)Perl 文档松散地称为 shell 的实例元字符;在这种情况下,?和{和}- 请参阅perldoc -f system。它在这里不起作用的最可能原因是 OP 的sh不识别大括号扩展(这是 Bash/Ksh/Zsh 扩展),因此该模式不匹配任何内容并被视为文字,正如解释在dataless' answer.