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

前端 未结 7 1727
误落风尘
误落风尘 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:35

    You can enable rudimentary command line argument with the "s" switch. A variable gets defined for each argument starting with a dash. The -- tells where your command line arguments start.

    for d in 1 2 ; do 
      cat someFile | perl -slane ' print "$someParameter: OK" if /hdisk$someParameter\s+/' -- -someParameter=$d; 
    done
    

    See: perlrun

提交回复
热议问题