zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: protect spaces and/or globs
Date: Thu, 11 Feb 2021 11:48:35 -0800	[thread overview]
Message-ID: <0d053511-25cf-4d4e-7f57-1823c915fec3@eastlink.ca> (raw)
In-Reply-To: <544A50D4-7F71-4763-8DEC-D5D99E4AE7CC@larryv.me>

On 2021-02-11 9:19 a.m., Lawrence Velázquez wrote:
>
> Why are you still accreting grepargs like this? Peter has already
> shown you how to do this.
>
> 	grepargs=("$@")
>
> Unless your actual code actually modifies the args before adding
> them to the array?
Not modified but the ordering is different so I hafta grab them one at a 
time.
Good point tho, all else equal I see that Peter's method is better.
> 	[...]
>
> 	% pat='on the current' foo='i,2,light edit' bar='i,1,old stable'
> 	% grep_wrapper $pat $foo $bar
>
> 	what should be going to history:
> 	grep --color=always -i -- 'on the current' 'i,2,light edit' 'i,1,old stable'
Yes, point made.  I know that if I want something expanded I don't 
single quote it. But indeed
I shouldn't say 'exactly as typed' because I know that variables will be 
expanded.

> 	[...]
>
> A ${(q-)foo} expansion basically re-quotes the value of foo so
> it works correctly with eval, in whatever way is requested. It
> doesn't know the value's origins.
That's a subtle but important point.  I could think of it as 
'protection' but then
how did the variable expand?  As you say it must be seen as re-quoting.  
Thanks
for catching it.
> That's not how quoting works. Quote levels don't nest to produce
> some kind of super-quoting. You're misinterpreting the results of
> your experimentation.
>
> 	% foo='a b c'
> 	% print -r 'protected: $foo'
> 	protected: $foo
> 	% print -r "'not protected: $foo'"
> 	'not protected: a b c'
>
> The double quotes do protect the single quotes from being interpreted
> by the shell, but they also permit expansions.
That is a critical point.  You know, it is so easy to think you've 'got 
it' when you don't.
I'm going to take the above and write it to a sticky note a stick it to 
my desk.  Very
insightful of you to realize that I'm not seeing things right, many thanks.



  reply	other threads:[~2021-02-11 19:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 20:42 Ray Andrews
2021-02-09 21:05 ` Lawrence Velázquez
2021-02-09 21:08 ` Peter Stephenson
2021-02-09 23:45   ` Ray Andrews
2021-02-10  0:22     ` Lawrence Velázquez
2021-02-10  0:51       ` Ray Andrews
2021-02-10  1:46         ` Lawrence Velázquez
2021-02-10  2:25           ` Ray Andrews
2021-02-10  2:52             ` Lawrence Velázquez
2021-02-10  1:52         ` Greg Klanderman
2021-02-10  2:29           ` Ray Andrews
2021-02-10 15:18           ` Ray Andrews
2021-02-10 15:47             ` Peter Stephenson
2021-02-10 16:19               ` Ray Andrews
2021-02-10 16:29                 ` Peter Stephenson
2021-02-10 20:53                   ` Ray Andrews
2021-02-10 22:14                     ` Bart Schaefer
2021-02-11 16:31                       ` Ray Andrews
2021-02-11 17:19                         ` Lawrence Velázquez
2021-02-11 19:48                           ` Ray Andrews [this message]
2021-02-10 18:08                 ` Bart Schaefer
2021-02-10 20:56                   ` Ray Andrews
2021-02-10 16:28             ` Lawrence Velázquez

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=0d053511-25cf-4d4e-7f57-1823c915fec3@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).