From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: preserving single quotes
Date: Wed, 28 Sep 2022 07:32:41 -0700 [thread overview]
Message-ID: <0ede34f7-4684-8b48-700e-9555cccfa693@eastlink.ca> (raw)
In-Reply-To: <20220928100020.tn3debb7jkytyluz@chazelas.org>
On 2022-09-28 03:00, Stephane Chazelas wrote:
> Use ${(Q)${(z)dd}} instead of $=dd. See `man zshexpn` for the meaning
> of (z) and (Q).
>
> Roman.
Didn't work.
>
> Use either:
>
> dd() aptitude search '?name(libreoffice-java-common)'
> ee=$(dd)
Cool. So we can just create a little impromptu function. Never tried
that but it works. I sorta understand that since the string isn't being
handed off to something else, zsh doesn't feel the need to strip off the
quotes -- the function is just as written.
>
> Or:
>
> dd="aptitude search '?name(libreoffice-java-common)'"
> ee=$(eval -- $dd)
My old friend eval. But Bart advises to get away from it. Anyway it
works for now.
> Or:
>
> dd=( aptitude search '?name(libreoffice-java-common)' )
> # or
...
> ee=$( "$dd[@]" )
Works. But that puzzles me, it seems simplest, but how is that that
saving the aptitude string as an array preserves the single quotes? It
seems unintuitive that the method of saving the string would make the
difference.
> $=dd just does $IFS-splitting. If $dd is meant to contain shell code,
> you should use eval to evaluate it. But to store code, you
> generally use functions not variables. The z and Q parameter
> expansion flags can do the same tokenisation and quote removal
> as the shell syntax parser does, but I don't think you want to
> go there.
I've never had anything but grief in the Q continuum. Hard to express
it, but it all seems so .... ad hoc, vague, Rube Goldberg, full of
gotchas -- (qqq) doesn't work on Mondays -- impossible to remember,
forced ... but your solutions above are crisp, and understandable and
rememberable.
Thanks gentlemen both.
next prev parent reply other threads:[~2022-09-28 14:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 3:12 Ray Andrews
2022-09-28 9:10 ` Roman Perepelitsa
2022-09-28 10:00 ` Stephane Chazelas
2022-09-28 14:32 ` Ray Andrews [this message]
2022-09-28 18:49 ` Stephane Chazelas
2022-09-28 19:29 ` 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=0ede34f7-4684-8b48-700e-9555cccfa693@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).