简体   繁体   中英

perl input from STDIN pipe only works with perl in front of script

I am attempting to read from STDIN with a perl script.

Here is the script I am using for testing:

#!/usr/bin/perl

foreach $line (<>) 
{
  print $line;
}

So from the command prompt, I type:

> cat somefile | testscript
>

It returns nothing with no error.

I then type the following:

> cat somefile | perl testscript
> *the contents of the file are printed line by line*

I really do not want the users to have to append perl in front of the script if I do not have to.

Thanks for reading.

I think you run two different versions of Perl. What is the output of "which perl"?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM