zsh-workers
 help / color / mirror / Atom feed
* Brace expansion in command position
@ 2020-11-21 15:31 Daniel Shahaf
  2020-11-21 17:56 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2020-11-21 15:31 UTC (permalink / raw)
  To: zsh-workers; +Cc: Felipe Contreras

[[[
% 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.

Cheers,

Daniel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Brace expansion in command position
  2020-11-21 15:31 Brace expansion in command position Daniel Shahaf
@ 2020-11-21 17:56 ` Peter Stephenson
  2020-11-23  4:05   ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2020-11-21 17:56 UTC (permalink / raw)
  To: zsh-workers

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 :-).)

pws



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Brace expansion in command position
  2020-11-21 17:56 ` Peter Stephenson
@ 2020-11-23  4:05   ` Daniel Shahaf
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2020-11-23  4:05 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-23  4:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-21 15:31 Brace expansion in command position Daniel Shahaf
2020-11-21 17:56 ` Peter Stephenson
2020-11-23  4:05   ` Daniel Shahaf

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git