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

Re: Compound Glob Specifiers

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