[英]How to pipe stdin into a perl script that is looking for input as the only parameter?
[英]perl input from STDIN pipe only works with perl in front of script
我正在尝试使用Perl脚本从STDIN中读取。
这是我用于测试的脚本:
#!/usr/bin/perl
foreach $line (<>)
{
print $line;
}
因此,在命令提示符下,键入:
> cat somefile | testscript
>
它不返回任何错误。
然后输入以下内容:
> cat somefile | perl testscript
> *the contents of the file are printed line by line*
我真的不想让用户不必在脚本前附加perl。
谢谢阅读。
我认为您运行两种不同的Perl版本。 “哪个perl”的输出是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.