zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: "Lawrence Velázquez" <larryv@zsh.org>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH?] Nofork and removing newlines
Date: Thu, 7 Mar 2024 09:26:18 +0100	[thread overview]
Message-ID: <CAHYJk3SDs7Sz_6TnMTC7e9cf+C8XzJGs=_Cz7wYkK+p4ChEwgg@mail.gmail.com> (raw)
In-Reply-To: <faf16db0-9527-46b2-b73f-cb321e73a78b@app.fastmail.com>

On 3/7/24, Lawrence Velázquez <larryv@zsh.org> wrote:
> On Wed, Mar 6, 2024, at 5:22 PM, Mikael Magnusson wrote:
>> "${ foo}" and ${ foo} having the same wordsplitting behavior but only
>> differing in stripping newlines feels a bit magical and weird.
>
> I agree.  Personally, I'm always surprised when quoting does anything
> other than suppress splitting, globbing, and special characters in
> patterns.  For instance, I can never remember this pitfall mentioned
> in workers/52666, even though (I think) I understand why it happens:
>
> 	% print ${:-{}x}
> 	{}x
> 	% print "${:-{}x}"
> 	{x}

This is not really an effect of quoting per se, really it's just luck
that the unquoted form works. You'll notice that if you try print
"${:-}x}" without the quotes it will simply fail. Your example only
happens to pass the parsing stage because the braces are balanced
which they have no inherent reason to do in what is supposedly a
string literal. Because the parser "knows" about the balanced braces
in the unquoted case, it skips past the first } for closing the ${,
but in the quoted form the { is not special in any way, so the first }
does match the ${, and then the second } is just a literal } which is
then printed after the x.

The correct way to write it in both cases would be:
% print ${:-\{\}x}
{}x
% print "${:-{\}x}"
{}x

(you can \escape the { inside the quotes too if you want, but it has
no effect on the result).

-- 
Mikael Magnusson


  reply	other threads:[~2024-03-07  8:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  5:52 Bart Schaefer
2024-03-05  6:56 ` Stephane Chazelas
2024-03-05 22:48   ` Bart Schaefer
2024-03-06 17:57     ` Stephane Chazelas
2024-03-06 19:45       ` Bart Schaefer
2024-03-06 22:22         ` Mikael Magnusson
2024-03-06 22:42           ` Bart Schaefer
2024-03-07  4:53           ` Bart Schaefer
2024-03-07  7:02             ` Lawrence Velázquez
2024-03-07  8:09               ` ${<file} (Was: [PATCH?] Nofork and removing newlines) Stephane Chazelas
2024-03-08  1:29               ` [PATCH?] Nofork and removing newlines Bart Schaefer
2024-03-08 22:15                 ` Oliver Kiddle
2024-03-08 23:28                   ` Bart Schaefer
2024-03-09 20:43                     ` Oliver Kiddle
2024-03-10  6:11                       ` Bart Schaefer
2024-03-12 17:54                         ` Bart Schaefer
2024-03-12 23:19                           ` Oliver Kiddle
2024-03-13  4:13                             ` Bart Schaefer
2024-03-14 22:15                               ` Oliver Kiddle
2024-03-15  8:42                                 ` Stephane Chazelas
2024-03-27  1:16                                   ` Bart Schaefer
2024-03-27  7:05                                 ` Bart Schaefer
2024-03-07  7:10             ` Stephane Chazelas
2024-03-08  0:37               ` Bart Schaefer
2024-03-07  6:52           ` Lawrence Velázquez
2024-03-07  8:26             ` Mikael Magnusson [this message]
2024-03-07 19:02               ` Bart Schaefer
2024-04-02  6:45                 ` Lawrence Velázquez
2024-03-06 19:43     ` Stephane Chazelas

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='CAHYJk3SDs7Sz_6TnMTC7e9cf+C8XzJGs=_Cz7wYkK+p4ChEwgg@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=larryv@zsh.org \
    --cc=zsh-workers@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).