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


i have file, somefile, this:

$cat somefile hdisk1 active hdisk2 active 

i use shell script check:

$cat a.sh #!/usr/bin/ksh d in 1 2     grep -q "hdisk$d" somefile && echo "$d : ok" done 

i trying convert perl:

$cat b.sh #!/usr/bin/ksh export d d in 1 2     cat somefile | perl -lane 'begin{$d=$env{'d'};} print "$d: ok" if /hdisk$d\s+/' done 

i export variable d in shell script , value using %env in perl. there better way of passing value perl one-liner?

you can enable rudimentary command line argument "s" switch. variable gets defined each argument starting dash. -- tells command line arguments start.

for d in 1 2 ;    cat somefile | perl -slane ' print "$someparameter: ok" if /hdisk$someparameter\s+/' -- -someparameter=$d;  done 

see: perlrun


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -