zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: unmatched '
Date: Fri, 9 Mar 2018 12:23:10 -0800	[thread overview]
Message-ID: <CAH+w=7ZSyniDaVOgKhzPrdchv2gtVM0G0+JgwwJXYOYctvgg+g@mail.gmail.com> (raw)
In-Reply-To: <2dcec644-7acb-5916-2858-2301206f1da8@eastlink.ca>

On Fri, Mar 9, 2018 at 9:50 AM, Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> $ c etc
>
> (eval):1: unmatched '
>
> I suspect this abomination:
>
> /etc/DSHR's Blog: Using the official Linux overlayfs_files
>
> ... God knows why that's permitted, but I'm thinking that the single quote
> is doing the obvious thing as far as 'eval' in concerned.  Can I prevent
> that?  Or, if it must be an error, can I get eval to ignore it somehow? The
> offending line is this:
>
> baz=(`eval print -l $bar $grepstring`)

You really should never do this with "eval".  Consider what happens if the
file name is /etc/Why you should never `rm -rf /`

(Obligatory warning:  DO NOT TRY THAT AT HOME.)

Why are you putting stuff like that file in /etc/ in the first place?
It's not meant to be a scratch or documentation directory, it's
supposed to contain system-wide configuration files.
https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

> ... I want to sent the output of printing '$bar' after it's been piped
> through the chain of greps that are built up and saved in the '$grepstring'

If $bar is a file name with spaces in it, `eval print -l $bar` is
going to split the name up on the spaces and write one "word" of the
file name on each line.  Is that actually what you intend?  Otherwise
unless $bar is an array, you don't need the -l option of print,
because you're always printing just one line anyway.

If $bar is a file name that begins with a hyphen, "print" is going to
try to interpret that as options.

Based on your description there must be a leading "|" in $grepstring.
Don't do that.

Assuming you've carefully sanitized $grepstring to avoid gotchas like
unintentional `...` or $(...) substitutions, the closest you should
ever get to what you're doing is

baz=( `print -lr -- "${bar[@]}" | eval "$grepstring"` )

There's probably a better way to do your cascade of greps, too, such
as building a file with one pattern per line and running a single
"grep -f patternfile", but you haven't provided sufficient context.


  reply	other threads:[~2018-03-09 20:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 17:50 Ray Andrews
2018-03-09 20:23 ` Bart Schaefer [this message]
2018-03-09 22:45   ` Ray Andrews
2018-03-09 23:12     ` Ray Andrews
2018-03-10  3:20     ` Aaron Schrab
2018-03-10  3:51       ` Ray Andrews
2018-03-10 17:40         ` 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='CAH+w=7ZSyniDaVOgKhzPrdchv2gtVM0G0+JgwwJXYOYctvgg+g@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=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).