When is ** understood by file glob()? When is ** understood by file glob()? shell shell

When is ** understood by file glob()?


In POSIX shell:

The slash character in a pathname shall be explicitly matched by using one or more slashes in the pattern; it shall neither be matched by the asterisk or question-mark special characters nor by a bracket expression

You could google: "filename expansion pattern".

In bash you could set globstar:

[An asterisk] Matches any string, including the null string. When the globstar shell option is enabled, and ‘*’ is used in a filename 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.

$ shopt -s globstar$ ls **/$ shopt -u globstar$ ls **/

note: '/' is used here to show only directories.


** is interpreted as (*/)# (zero or more directories) in Zsh's extended glob syntax, which is implemented in Zsh-specific C code (Src/glob.c). This behavior is not optional.

When shopt -s globstar is enabled in Bash, it acts similarly in Bash's extended glob syntax, which is implemented in Bash-specific C code (pathexp.c). This is off by default.

In traditional UNIX glob, ** is interpreted the same as *.