Shell globs
Globs, is associated with certain kinds of 'match this pattern'.
- also called shell globs, because they are mainly seen in command lines
Compare with regular expressions, which are more powerful (but still single-string) ways of expressing patterns.
Shell globs
Shell globs match fairly simple patterns. you can only use:
- ? meaning one character of anything, and
- * meaning any amount of characters of anything
- ...anything except the directory separateor, / {{(or presumably \ if imitated in windows)}}
- [chars] meaning any one of the characters in this set
- can also be used to match a literal ? or *
- [!chars] meaning anything other than the characters in this set
If you have both a fnmatch and glob function:
- fnmatch() is a "matches a single given string with this pattern"
- (probably nothing related to the filesystem unless you do it yourself)
- glob() is likely to read directory entries from your filesystem and returns all matching filenames
- apparently fnmatch() is used in the glob() implementation
Modern globs
The classics mentioned above existed since the 1970s.
People have tried to extend it occasionally.
Most such extensions ended up local to a specific shell, language, or such.
A few did get picked up more widely.
No single adopted standard, so you still have to read the manual of what is supported, but the common addition is:
- ** meaning 'any number of path segments', i.e. recursing
- (frequently called globstar matching)
and to a lesser degree:
- {a,b} matching alternatives
You see this in
various ignore files,
things like git's pathspec,
bash in 2009(verify)[2]
python's glob.glob since 2015ish [3]
node in