From: Bart Schaefer <schaefer@brasslantern.com>
To: linuxtechguy@gmail.com
Cc: zsh <zsh-users@zsh.org>
Subject: Re: quoting question
Date: Tue, 12 Sep 2023 13:06:58 -0700 [thread overview]
Message-ID: <CAH+w=7bAU3GJAMzTsaKKFs7S9fh2+Q_8wbqHR4=aU1HJXwXGUQ@mail.gmail.com> (raw)
In-Reply-To: <CA+rB6GK9_BvEWc7LzO46rTdBx9L4aBP1YPgaCSruP-mG5wQdLA@mail.gmail.com>
On Tue, Sep 12, 2023 at 11:46 AM Jim <linux.tech.guy@gmail.com> wrote:
>
> Zsh quoting at times makes me wonder. Do quoting? Don't do quoting?
> The following case has me scratching my head. Can someone explain what is
> going on?
This doesn't directly have to do with quoting, rather it has to do
with ${param} expansion and brace expansion. The short answer is you
should never have unquoted { } inside the ${...}, because the first }
encountered is usually going to be interpreted as a match to the ${
and not to any other { in the string. Where double-quoting gets
involved is because inside a double-quoted string, none of the pairs
of { } have been tokenized, so the lexer can't distinguish which of
the two }} is the actual end of the expansion.
That's what happens here:
> DT="${(%):-%D{%Y-%m-%d %H:%M:%S %Z}}"
> print $DT
> 2023-09-12 13:21:40 CDT} <-- why "}" when quoted
The string is read as ${(%):-%D{%Y-%m-%d %H:%M:%S %Z} followed by }
because the %D{ is quoted (not tokenized) so does not lexically match
with any closing }, so the first one ends the ${...}.
In this case:
> DT=${(%):-%D{%Y-%m-%d %H:%M:%S %Z}}
> print $DT
> 2023-09-12 13:21:40 CDT
The inner { } are tokenized and checked for whether they constitute an
{x,y,z} brace expression. There's no comma, so they're left alone as
a matching pair, and the final } matches the opening ${. You can see
this by inserting a comma:
DT=${(%):-%D{%Y-%m-%d, %H:%M:%S %Z}}
Now %H becomes the home directory instead of the hour, etc.
If you setopt ignorebraces you'll see that all five examples work the
same and always leave the extra } at the end.
next prev parent reply other threads:[~2023-09-12 20:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 18:45 Jim
2023-09-12 20:06 ` Bart Schaefer [this message]
2023-09-13 2:50 ` Jim
2023-09-13 3:41 ` Bart Schaefer
2023-09-13 15:09 ` Debug zsh (was: Re: quoting question) Pier Paolo Grassi
2023-09-13 15:28 ` Mikael Magnusson
2023-09-13 11:28 ` quoting question Jim
2023-09-13 16:11 ` Bart Schaefer
2023-09-12 20:07 ` Peter Stephenson
2023-09-12 20:23 ` Bart Schaefer
2023-09-12 20:29 ` Bart Schaefer
2023-09-13 1:56 ` Mikael Magnusson
2023-09-13 8:50 ` Peter Stephenson
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='CAH+w=7bAU3GJAMzTsaKKFs7S9fh2+Q_8wbqHR4=aU1HJXwXGUQ@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=linuxtechguy@gmail.com \
--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).