Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Brace expansion in command position



Peter Stephenson wrote on Sat, Nov 21, 2020 at 17:56:35 +0000:
> On Sat, 2020-11-21 at 15:31 +0000, Daniel Shahaf wrote:
> > [[[
> > % type pwd
> > pwd is a shell builtin
> > % {pwd,-P}
> > zsh: command not found: pwd,-P
> > % builtin {pwd,-P}
> > /home/daniel
> > ]]]
> > 
> > I expected the second command to do what the third command does.
> 
> "{" in command position introduces a list to be run in the current
> shell, not a brace expansion.  So this is treated as { ... } where the
> ... here is the single-word command "pwd,-P" as a comma has no special
> meaning at this point.
> 
> Actually, other shells require a space after the "{", as well as a
> command terminator ";" or newline before the "}", but zsh doesn't.
> Other shells don't need a space or terminator in the subshell form,
> with parentheses (...), so this is another of those minefields it's
> quite hard to pronounce definitely on.  (This may not stop other people
> trying, excuse me if I don't take the bait :-).)

It's okay, there are plenty of fish in the sea ;-)

Seriously, thanks for the answer.  This seems to be partially covered
by A02alias.ztst:"Aliasing reserved tokens", but I don't see any test
specifically about this, so:

diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 35a04e7d5..c9a381812 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -939,3 +939,8 @@ F:Note that the behaviour of 'exit' inside try-list inside a function is unspeci
  $ZTST_testdir/../Src/zsh -fc '{ ( ) } always { echo foo }'
 0:exec last command optimization inhibited for try/always
 >foo
+
+ function 'ls,/' () {echo success}
+ {ls,/}
+0:current-shell blocks masquerading as brace expansion (test to ensure behaviour changes aren't unintentional)
+>success




Messages sorted by: Reverse Date, Date, Thread, Author