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

Re: Bug? Unexpected globbing duplicates



On Sat, Feb 12, 2022 at 12:32 PM <andykluger@xxxxxxxxx> wrote:
>
> I encountered a surprising result while using a glob expression, with
> extended globs enabled, of duplicate resulting elements
> [...]
> % print -rl -- **/**/*

The **/ operator is done by recursive descent, so if it appears more
than once it'll re-scan everything below the second (or third, etc.)
occurrence as the stack is unwound.  I suspect it'd make globbing
noticeably slower to check every new result against those already
found.  There might be a way to do it just for already-visited
directories that wouldn't add too much overhead.

It might also be possible for the glob-pattern parser to keep track of
when it's already seen **/ or (*/)# and treat further repetitions as
plain */ but that doesn't cover something like (*/)#(bar/)# ... I
suspect it's better to just do what the user wrote, there are other
ways to remove duplicates.




Messages sorted by: Reverse Date, Date, Thread, Author