Re: How do I (*|*/*) ?

Philippe Altherr <[email protected]> Mon, 13 Apr 2026 00:55:13 +0200
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CAGdYchsDbTjkGwF6p6VsJJknWUoLZZmFXsFnGrj1k6OoFcP4uQ@mail.gmail.com>
The documentation of (...) states the following:

Note that grouping cannot extend over multiple directories: it is an error
> to have a ‘/’ within a group (this only applies for patterns used in
> filename generation). There is one exception: a group of the form (pat/)#
> appearing as a complete path segment can match a sequence of directories.
> For example, foo/(a*/)#bar matches foo/bar, foo/any/bar,
> foo/any/anyother/bar, and so on.


This explains the bad patterns.

 My original quest is something like: print -l
> (*|*/*|*/*/*)/.DS_Store(OL[1,5])


You can use ** instead of (*|*/*|*/*/*) but it won't limit itself to a
maximum of 3 directories (see Recursive Globbing
<https://zsh.sourceforge.io/Doc/Release/Expansion.html#Recursive-Globbing> for
more details). If the limiting is crucial, you can do that afterwards by
filtering the result with ${name:#pattern}. In that pattern, (*|*/*) will
be accepted.

Philippe