Documentation for double asterisk glob expansion
Where can I find documentation on double asterisk in glob expansion?
- It is discussed in the .gitignore section of Pro Git.
- It works in
ls **/*
to list all terminal files. - It is supported by python's glob library.
Despite this, I cannot find mention of it in the glob man pages.
2 answers
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
mcp | (no comment) | Sep 6, 2023 at 16:30 |
The ** pattern is an extension to, not a part of, the POSIX glob syntax. While it has emerged as an informal standard, AFAIK there is no single standard to reference to describe what it does.
This means you'll need to consult the documentation for each application that uses it.
- For .gitignore files: https://git-scm.com/docs/gitignore#_pattern_format
- For
ls **/*
, this is actually your shell doing glob expansion.- Bash treats this identically to
ls */*
unless theglobstar
option is set, documented undershopt
- Zsh: https://zsh.sourceforge.io/Doc/Release/Expansion.html#Recursive-Globbing
- Other shells: do your own research
- Bash treats this identically to
- For Python's glob library, you've already linked to the relevant documentation.
0 comment threads
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
mcp | (no comment) | Sep 6, 2023 at 16:30 |
While *
belongs to the POSIX standard, **
is an extension. You are right it's not in man 7 glob
. Tools that treat **
specially (i.e. not as *
simply followed by *
) tend to agree what it means, but AFAIK it's only because there is a consensus, not because they all use some common library (like glob()
mandated by POSIX) whose documentation could be the ultimate answer to your question.
I'm afraid the best you can get is the documentation of each tool, separately. The links you posted are exactly this.
None of your links covers ls **/*
though. This example works because the shell expands **/*
before ls
is even started. You tagged bash
, therefore I assume your shell is Bash. For Bash these are the relevant fragments of the documentation:
*
Matches any string, including the null string. When theglobstar
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.
(source)
globstar
If set, the pattern**
used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a/
, only directories and subdirectories match.
(source)
Any other shell (or whatever tool) that supports **
shall document it for itself.
Notes:
-
Because
**
is an extension, some tools by default suppress their support unless you explicitly enable it. E.g. here (it's one of the links you posted) we can read "Ifrecursive
is true, the pattern**
will …"; but by defaultrecursive=False
. Similarly in Bash**
is by default just*
followed by*
, this changes when you invokeshopt -s globstar
. -
There is no guarantee all tools that treat
**
specially will expand it in exactly the same way. In general there may be edge cases and nuances. Always refer to the documentation of the tool you're actually using.
0 comment threads