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

Re: protect spaces and/or globs



> On Feb 9, 2021, at 7:51 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> 
> On 2021-02-09 4:22 p.m., Lawrence Velázquez wrote:
>> For the less clairvoyant of us, your refusal to reveal anything but
>> the smallest slice of your actual code makes it rather difficult
>> to help.
>> 
> I'm trying to keep is as simple as possible because the totality of the thing doesn't
> matter, just the specific problem.

Imagine developing stomach pain, self-diagnosing an ulcer, and
refusing to answer doctors' questions about medication, diet,
existing conditions, or anything not ulcer-related because you're
"trying to keep it as simple as possible because the totality of
the thing doesn't matter, just the specific problem", which you
have already decided is an ulcer and cannot possibly be anything
other than an ulcer.

> When a function argument will end up making
> an argument to grep, and the argument to grep must have single quotes, but the single
> quotes typed in the function argument are stripped off. What's the solution? grep must
> have " $ grep 'file name'  " with intact quotes but zsh always strips them off.

grep does not need those arguments to have single quotes. It needs
them to remain a single word, which is related but not identical.

> There
> must be a solution.  Or perhaps I'm stuck with " $ grep 'file\ name' -- seems the single
> quotes preserve the backlash which in turn forces 'file name' to be a single word as
> wanted.  It's ok, but I wonder if there's a better way.  I thought the (q) flag might
> do it.  Memory tickles that I learned how to do this once.
> 
> Hey, just fiddling around with it right now and:
> 
> $ g ,H 'execute' "'g,46,w4 now default'" f
> ... double quote the single quotes and the single quotes remain. Logical too, outer
> quotes will be stripped, so just throw in another set.  Final grep is:
> 
> GREP_COLOR='01;33' grep --color=always -iFIHn -d skip -- 'execute' 'g,46,w4 now default' f
> ... all good.

It sure sounds like you're assembling a scalar and eval-ing it, but
who's to say. (q) works fine in this toy example.

	% () { eval "print -rC1 -- $@" } a 'b c' d 'e f g'
	a
	b
	c
	d
	e
	f
	g
	% () { eval "print -rC1 -- ${(q)@}" } a 'b c' d 'e f g'
	a
	b c
	d
	e f g

--
vq



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