Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Use glob patterns while reading a file
- X-seq: zsh-users 23751
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Use glob patterns while reading a file
- Date: Sat, 10 Nov 2018 01:21:18 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:references:subject:date :in-reply-to; s=fm1; bh=kYXTyuuLIgsEZym2vpDMpsP48AMMFTrS6t7eRqGk UVY=; b=cchLdRJgJN4Vodn+QK4KMmSJ1gBw5C34MMyLD3x+dacSZZhDLn7K7QID eSbOxjga4qEtVoOwc7B+u3EqO4/F18bN56L9VinmYXR/eLiEhhng06EXtJbEugzG qJ+oTdsuU+1n0Ybn4zeJ6ABYq1a9ILRHs7254ZvuGnLfyzYUYutdx7cenF3OSHFh 8QewwUlQzXJ3wI2LmEbC4q80ZOT/f06v4EPqS50wxx0cPVuOZhN1CTbzR7JXUMcH do9Bf1zLwNBh8BtZgPvX6mvM4BCqfuLK8Ii633x+hcc8jycm0kW8tKLwsYa37lx0 jSUizao9QWJXh9EyNBAZnuRdMRNA6g==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=kYXTyuuLIgsEZym2vpDMpsP48AMMFTrS6t7eRqGkU VY=; b=n13vOtDy8g2p8eeaP2O8IHbt4YtuWpxvvPvPqbR0dxwYZ3PTPICQ4WAMF DpeyM6v5zhxdv5L4I0DcAQhONgMssGYXvJ4hqG9nH744eqt4LWxXGadF5aXHpldt c0ucm9N488Hx1m5WsQ2miZ9+sbvbtCYIIzSkFFTgIkh/DOCIYVelML2lgm8AMvC7 +A6ns+1z7W6r/15FZO7oE3wl5yIx6GyJkXEXU84DfWiSFeAsYZJWgj452KWpX8nT ArzvJj2vzcZCz0ZPyrtTiq+5cxJXB/pWosxabetUy3klxsEPsyPDG2qjHSr9WcUV TOCrSxXnUtXnexcVxHpEbdz2cMvxQ==
- In-reply-to: <1541756153.3720.1.camel@samsung.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20181108225555epcas2p274de218aef35e46f189ebbfbd9d1892f@epcas2p2.samsung.com> <CAJjRh0SROuSoc4f+3bqLNsc+iASx7MRULrNWqdPjK+MKFHys7A@mail.gmail.com> <1541756153.3720.1.camel@samsung.com>
Peter Stephenson wrote on Fri, 09 Nov 2018 09:35 +0000:
> On Thu, 2018-11-08 at 23:53 +0100, Dominik Ritter wrote:
> > I want to use read one of two files, regardless if it exists or not. My
> > first approach is to use the alternative glob syntax, but with no luck:
> > $(< ./(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. The forms «foo» and
«print -r -- "$(<foo)"» should always be equivalent (assuming 'foo' outputs
a trailing newline). Similarly, «<foo» and «<foo $READNULLCMD» are usually
equivalent, but «$(<*)» and «$(<* $READNULLCMD)» are not.
(I know that $(<foo) is optimised, but the whole point of optimisations is that
they don't change the semantics.)
By default, «*» after «<» is a glob. There is no reason for a user to expect
«$(<*)» to be different: neither command substitution nor input redirection
implies 'noglob' or NO_MULTIOS in any other situation.
Frankly, I'm tempted to treat it as a bug — but before I jump to conclusions,
was this behaviour intentionally implemented this way?
>
The manual says:
.
The substitution `tt($LPAR()cat) var(foo)tt(RPAR())' may be replaced
by the equivalent but faster `tt($LPAR()<)var(foo)tt(RPAR())'.
.
which is correct only when var(foo) does not involve globbing. I don't want to
open the user manual v. reference manual can of worms again, but I think there
is room for improvement here.
> You can get it to work with
>
> $(cat <./(a|b)(N))
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author