bashunixminimatchshopt

Bash globstar matching after text


I really can't understand why pattern test**/*.ext matches test23/file.ext, but doesn't match test23/test/file.ext and test23/test/test/file.ext. Globstar should match all of this, shouldn't it?


Solution

  • Here's man bash:

    When the globstar shell option is enabled, and * is used in a pathname expansion context, two adjacent *s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a /, two adjacent *s will match only directories and subdirectories.

    Since your ** is not a single pattern but rather a part of test**, it does not get the globstar treatment.