From: Oliver Kiddle <opk@zsh.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Nofork ${{var}...} edge cases
Date: Wed, 27 Mar 2024 23:22:40 +0100 [thread overview]
Message-ID: <42966-1711578160.323146@w_2U.aZv1.yyMw> (raw)
In-Reply-To: <CAH+w=7YHZspc2JVBxkkYO69Cr9x__s-m4UQqRUfOetZYssUqnw@mail.gmail.com>
Bart Schaefer wrote:
> Just seeking opinions:
>
> Should ${{} true} (empty variable name) result in "bad substitution"?
Given that ${} just outputs nothing, the current behaviour of also
outputting nothing is entirely consistent.
That is just a zshism, however:
ksh: syntax error: `}' unexpected
bash: ${}: bad substitution
/bin/sh: ${}: Bad substitution
I prefer zsh's behaviour here - ignoring the error - but would guess the
reason for it may be related to the support for nested substitutions. And
while uses of ${} alone are rare, variants such as ${:-xx} are useful.
Your patch doesn't allow a substitution inside the {}, however so nested
substitutions are not a reason here.
> Otherwise it's all side-effects, because nothing will be substituted.
> The prior ${|| true} form was a parse error.
>
> Should ${{var}} be a "bad substitution", or print a warning about an
> empty command? Otherwise it just substitutes $var.
Again, I think I prefer the approach of doing as the user says even if
it doesn't appear to make much sense - so just substitude $var. If that
produces an error, what about ${{var}$=CMD} where CMD is unset.
> What about ${{var};} or ${{var}{}} etc.?
And there's probably a further half-dozen ways we've not thought of.
> Or we could declare ${{REPLY}...} as NOT synonymous with ${|...} and
> localize REPLY only in the latter of those. That might actually make
> more sense.
That definitely makes most sense to me.
> Among the reasons I listed for not doing this, I forgot to mention
> that subscripts are allowed and you can't localize a subscripted
> parameter.
That's a fair argument for not making the parameter local.
Subscripts could be useful for something like:
print ${{a[i]} i=2}
If we want automatic local for the subscript then maybe ${{a[]} REPLY=2}
While ${{arr} ... } does return arrays, it doesn't appear to be possible
to force array output from ${| ... }
In mksh:
print ${|REPLY=(one two)}
does just print "one".
But various forms like ${${|REPLY=(one two)}[1]} return just "n"
I have built zsh with your latest patch and have not found any issues
with any tests I've thrown at it.
Perhaps worth including in a test case is the following which does
break after running the echo.
while :; do; echo ${|REPLY=x;break}; done
Oliver
next prev parent reply other threads:[~2024-03-27 22:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 18:57 Bart Schaefer
2024-03-27 22:22 ` Oliver Kiddle [this message]
2024-03-28 1:00 ` Bart Schaefer
2024-03-28 1:21 ` Bart Schaefer
2024-03-28 1:32 ` Bart Schaefer
2024-03-28 0:29 ` Mikael Magnusson
2024-03-28 1:12 ` Bart Schaefer
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=42966-1711578160.323146@w_2U.aZv1.yyMw \
--to=opk@zsh.org \
--cc=schaefer@brasslantern.com \
--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).