Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unmatched '



On Fri, Mar 9, 2018 at 9:50 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> 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.



Messages sorted by: Reverse Date, Date, Thread, Author