zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: greps pipes and eval bad patterns
Date: Sun, 25 Oct 2015 20:39:13 -0700	[thread overview]
Message-ID: <562DA061.2080109@eastlink.ca> (raw)
In-Reply-To: <CABx2=D-i9Rj2ZRUE+JQBC4qc2bF4DEKh4XZd1QF=rsV=EMiaiw@mail.gmail.com>

On 10/25/2015 06:17 PM, Kurtis Rader wrote:
> In addition to what Bart said I'll point out that it's usually easier and
> safer to avoid the eval by using an if/else block. Getting the quoting
> right when using eval can be very difficult. Especially if you don't have
> direct control over the text being eval'd; e.g., if some of it is supplied
> by the user; or even just built up from earlier parts of the function.
>
> I have several functions where 99% of the time I want the output
> automatically piped into my pager (e.g., /usr/bin/less). But if the output
> of the function is redirected away from my tty I don't want the pager in
> the pipeline. So instead of using a variable that would normally contain "|
> $PAGER" and sometimes be empty (i.e., using Ray's approach) I simply spell
> it out:
>
>      if [[ -t 1 ]] ; then
>        grep -h -E $case_insensitive -- "$search_for" $files | $PAGER
>      else
>        grep -h -E $case_insensitive -- "$search_for" $files
>      fi

That's exactly the sort of thing I did before in this sort of 
situation.  I take your caveats  seriously tho.  Mostly I was just 
interested in the problem for my education.  I can quite see that eval 
could do some weird stuff if the input was uncertain.  What matters most 
is that the code is clear both to read and to execute. Having a pipe 
inside a variable seems unsound.


  reply	other threads:[~2015-10-26  4:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-25 19:47 Ray Andrews
2015-10-26  1:02 ` Bart Schaefer
2015-10-26  1:17   ` Kurtis Rader
2015-10-26  3:39     ` Ray Andrews [this message]
2015-10-26  3:31   ` Ray Andrews
2015-10-26 13:04     ` ZyX
2015-10-26 13:36       ` Ray Andrews
2015-10-26 14:30         ` Bart Schaefer
2015-10-26 14:49           ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=562DA061.2080109@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).