How do I best pass arguments to a Perl one-liner?

前端 未结 7 1731
误落风尘
误落风尘 2020-12-05 05:27

I have a file, someFile, like this:

$cat someFile
hdisk1 active
hdisk2 active

I use this shell script to check:



        
7条回答
  •  粉色の甜心
    2020-12-05 05:36

    Pass it on the command line, and it will be available in @ARGV:

    for d in 1 2
    do
      perl -lne 'BEGIN {$d=shift} print "$d: OK" if /hdisk$d\s+/' $d someFile
    done
    

    Note that the shift operator in this context removes the first element of @ARGV, which is $d in this case.

提交回复
热议问题