Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Documentation for double asterisk glob expansion

+4
−0

Where can I find documentation on double asterisk in glob expansion?

  1. It is discussed in the .gitignore section of Pro Git.
  2. It works in ls **/* to list all terminal files.
  3. It is supported by python's glob library.

Despite this, I cannot find mention of it in the glob man pages.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

2 answers

+9
−0

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.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+5
−0

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 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.

(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 "If recursive is true, the pattern ** will …"; but by default recursive=False. Similarly in Bash ** is by default just * followed by *, this changes when you invoke shopt -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.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »