Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Compound Glob Specifiers
- X-seq: zsh-users 27335
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zach Riggle <zachriggle@xxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Compound Glob Specifiers
- Date: Tue, 9 Nov 2021 08:52:39 +0100
- Archived-at: <https://zsh.org/users/27335>
- In-reply-to: <CAMP9c5kG4cR7QxMu93cLeZn_4BmZht=toAijxj4GvnKbYMm5Gw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP9c5kG4cR7QxMu93cLeZn_4BmZht=toAijxj4GvnKbYMm5Gw@mail.gmail.com>
On 11/9/21, Zach Riggle <zachriggle@xxxxxxxxx> wrote:
> I expect this is a case of "you're holding it wrong", but I figure it's
> worth asking what the right way to do this is...
>
> I want to glob the equivalent of */*/somefile (not **/foo, specifically two
> directories deep).
>
> However, I do NOT want the glob to match if any of the directory components
> are a symlink.
>
> *(/) is the glob specifier for directories [1]
>
> It would then follow that *(/)/*(/)/somefile would match dir/dir/somefile
> and not dir/link/somefile.
>
> This is not the case -- even *(/)/ (i.e. appending a trailing slash to all
> directories) do not work out-of-the-box as one might expect.
>
> I've read through 14.8 Filename Generation [2] as best I can (my favorite
> hack being the NTREF=reffile bit) but haven't found anything that suggests
> how one might do this.
You can do this explicitly by
one=( *(/N) )
two=( $^one/*(/N) )
result=( $^two/somefile(N) )
or more cryptically
() { () { cmd $^@/somefile(N) } $^@/*(/N) } *(/N)
(this will run cmd even if there were no matches)
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author