CTO and co-founder of Signal Sciences. Author and speaker on software engineering, devops, and security.

Golang globs and the Double Star Glob Operator

Golang's glob library doesn't support the ** double-star or globstar operator. Here's how to get it.

The golang filepath/glob and filepath/match functions provide glob matching but does not support the "double star", "double asterisk", "globstar", "super glob", "super wildcard" operation that descends into other directories. According to Issue 11862 the problem seems to be handling edge cases like crossing file system boundaries, symlinks and infinite loops (if I read @rsc's comment correctly).

In the meantime, one of these packages might work:

In addition gobwas/glob is an excellent generic glob package that claims huge performance advantages over other globs and the equivalent regular expressions. It does not however provide a filewalker.

Happy globbing, and if you want to know more about the science of globs, @rsc wrote it up for you.

Notes

  • In bash 4, you can turn on globstar with shopt -s globstar
  • The latest macOS (10.12.4 10.13.3) uses a very old bash 3 and doesn't support globstar.
  • Java's FileSystem#getPathMatcher describes globstar in more detail.
golang software

© 2018 Nick Galbreath