Most Borne-style shells (of which zsh, bash, and ksh are some) will let you define an environment variable for a single command by prefixing the command itself with something like:
ACTION_PATTERN='perl$' perl -ne '$count++ if m{$ENV{ACTION_PATTERN}};END{print $count, qq{\n};}' ~/.zsh_history.You could do that here, but I'm wondering if there's not a bit of an XY problem in that you're wanting to use an arbitrary pattern in your search command and aren't sure how to pass that as an argument into your oneliner. If that were the case you could always do something like this and use shift to pull it out of @ARGV before the -n option starts iterating over things:
ROWS=$(perl -nE 'BEGIN{$PATTERN=shift();$PATTERN=qr/$PATTERN/;};$count +++ if m{$PATTERN};}{ say $count' 'perl$' ~/.zsh_history) echo "ROWS:$ROWS"
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re: Calling perl from zsh w/ vars
by Fletch
in thread Calling perl from zsh w/ vars
by k-man
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |