We use this command to run all tests using mocha: mocha ./src/test/**/*.js --recursive

Notice the double **. It works fine on any modern bash, except on the CI system which is a RedHat with GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu).

I read that v3 does not support double globstar.

  • I tried to enable it by executing shopt -s globstar
    • but failed saying shopt: globstar: invalid shell option name.
  • I asked the client's devops to update the bash
    • but he said "it doesn't show me that a new version of bash is available".
  • This other answer was not helpful.

Question: How can I execute a command with ** on a linux bash v3.*? Any workaround?

1 Answer 1


If it doesn't support globstar, then it doesn't support it.

However, most of the time you can adapt find, xargs, and/or similar tools. Your case is pretty simple, with everything under one directory, so:

find src/test -name "*.js" -exec mocha --recursive {} +

find src/test -name "*.js" -print | xargs -d '\n' mocha --recursive

(find puts the filenames in place of {}, and xargs appends them to the end. So in both cases, the repeated arguments must go at the end after all the --options, but that shouldn't be a problem for most programs.)

Alternatively, if running mocha once for every file is okay, then:

find src/test -name "*.js" -exec mocha {} --recursive \;

Compare -exec … \; (one file at a time) and the earlier -exec … + (as many as possible).

Note: In all above examples, the "*.js" has to be quoted because you want find to process it, not the shell.

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.