Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: unmatched '
On 09/03/18 12:23 PM, Bart Schaefer wrote:
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.)
I probably have a lot of improper constructions here, I use the first
thing that seems to work, and later I repent of various sins as they
become apparent. How would I best do that sort of thing?
Why are you putting stuff like that file in /etc/ in the first place?
Heck, not me! That's stock Debian, I'd not create a directory like that
on pain of damnation. Debian should not allow it either, IMHO.
If $bar is a file name with spaces in it,
$bar will start with a list of directories as originally output by
'find', so whatever my code, it has to handle whatever 'find' might find.
Based on your description there must be a leading "|" in $grepstring.
Don't do that.
Yeah:
ccolor=33 # Start with yellow, then blue, magenta, cyan.
for file in "$@"; do
# We colorize the already selected lines here:
grepstring="$grepstring | GREP_COLOR='01;'"$ccolor" grep $wwild
$ccase --color=always \"$file\""
(( ccolor++ )) # Next color.
done
... so I'm filtering and colorizing however many arguments there are to
the command, so each iteration must (?) begin with the pipe. And the
final string:
bar=(`eval "find -H -O3 / -warn -type d -ipath \"*$1*\""
$grepstring`)
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.
The $grepstring itself can't have any surprises (famous last words) but
the entire construction is of course suspect. I see you're shrinking
the target of eval to the minimum, that seems sensible on first
principals but I can't think of a way to get the first pipe outside of
$grepstring. The thing is just to turn a string into a command because
the only way I know to create flexible commands is by way of strings.
Anyway, is there no way of putting a global protection on nasty
characters inside the list of directories? I'm sure I did read about
that, but there's so much to remember.
BTW I started doing this sort of cascading colorization with a very
similar function I use to explore the history. I can refine the search
with as many strings as I want, and they all show up with different
colors, which is even useful, not just eye candy. The final array gets
fed to Sebastian's 'n_list' for selection. Quite indispensable to me.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author