Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Use glob patterns while reading a file
On Fri, Nov 9, 2018 at 5:22 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>
> > > $(< ./(a|b)(N))
> >
> > That's a special syntax, expecting a single file so that it doesn't try
> > to do globbing.
>
> I think this violates the principle of least surprise. Grammars should be
> composable and shouldn't have special cases.
Although I can't argue with this from a philosophical standpoint, I
find it astonishing to pretend that zsh ignores that philosophy only
in this particular case.
> The forms «foo» and
> «print -r -- "$(<foo)"» should always be equivalent (assuming 'foo' outputs
> a trailing newline).
I don't follow that at all. «foo» is a shell word. «print -r --
"$(<foo)"» is the contents of a file identified by the word «foo». In
what context are those equivalent?
> Similarly, «<foo» and «<foo $READNULLCMD» are usually
> equivalent, but «$(<*)» and «$(<* $READNULLCMD)» are not.
The distinction here is that $(...) is a substitution, not a subshell.
It's more like a quoting mechanism (i.e. `foo`). $(<foo) is NOT an
"optimization" of $({<foo}) (which does work exactly the way you think
it would, globbing-wise), and the "<" in that position in the
substitution is not a redirection operator, even though it looks like
one for mnemonic reasons. $(<...) is an entirely different thing,
just like $((...)) is a different thing, even though «$(» and «<» do
not have to be composed without whitespace to form a token.
> was this behaviour intentionally implemented this way?
Yes.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author