Kelly Mears

Glob

Wildcard pattern matching over filenames, similar enough to regular expressions to mislead.

Systems & Tooling2 min read213 words9 out · 6 in
also calledGlobbingWildcardPathspec

A glob is a wildcard pattern for matching paths: an asterisk matching within a segment, a double asterisk matching across segments, a question mark matching one character, and brackets enclosing a character class.

Globs resemble regular expressions and behave differently in ways that produce silent, confident errors.

Bracket syntax is a character class. A path containing literal square brackets — a routing convention in several frameworks uses them — is parsed as a set of characters, so the pattern matches nothing and any rule attached to it never applies. There is no error; the configuration block is simply inert.

Leading-directory matching applies only to literal patterns. In several tools a bare directory path means "everything under it", but the moment the pattern contains a wildcard it is matched against the whole path — so a pattern ending at a directory name matches zero files, forever, and any check built on it passes on every input.

Zero matches is success. A command whose pattern matched nothing exits cleanly, so a gate built on it reads as a guarantee.

The habit that closes all three: enumerate what the pattern matches before relying on it. Listing the matched files is a one-second command and converts an assumption into a count. See Vacuous Truth and Silent Failure.

See also3

Hand-picked in the note itself — the neighbours worth reading next.

Related4

Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.

Linked from6

Notes elsewhere in the wiki that reach for this one.