Hopefully I am not the only one that finds globs to misbehavior. If you'd asked me an hour ago, I would have been 99% confident that


would match all .js files in src and all subdirectories of src..but I am on MacOS and using Bash 3.2.57, and it's not matching more than one file.

Anyone know what might be wrong?

  • 2
    Your shell might be wrong. First enter zsh and then do your globbing. SCNR – Philippos Jul 18 '17 at 7:44
  • Haha :) i am stuck on bash for now – Alexander Mills Jul 18 '17 at 15:52

Bash 3.2 doesn't support globstar:

$ shopt -s globstar
bash: shopt: globstar: invalid shell option name

Without shopt -s globstar, ** is just a plain non-recursive glob.

The bash NEWS page says:

This is a terse description of the new features added to bash-4.0 since the release of bash-3.2. As always, the manual page (doc/bash.1) is the place to look for complete descriptions.

  1. New Features in Bash


    w. There is a new shell option: globstar. When enabled, the globbing code treats ** specially -- it matches all directories (and files within them, when appropriate) recursively.

You'll need to update your bash to at least 4.0 (probably install one from homebrew), or use find.

| improve this answer | |
  • is the shopt builtin specific to bash only, but the set builtin is part of posix, i.e. all "bourne" shells have it? – the_velour_fog Jul 18 '17 at 6:58
  • I don't know about other shells, but yes, shopt is not POSIX and set is. – muru Jul 18 '17 at 7:15

You could use find to do this instead. For example:

find ./test/src -type f -name \*.js

If you want to limit to only 2 directories deep:

find ./test/src -maxdepth 2 -type f -name \*.js
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.