Read more

Enabling ** in your bash

Arne Hartherz
January 10, 2017Software engineer at makandra GmbH

You may know the double asterisk operator from Ruby snippets like Dir['spec/**/*_spec.rb'] where it expands to an arbitrary number of directories.
However, it is disabled by default on most systems. Here is how to enable it.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

If you check your globstar shell option, it is probably disabled:

$ shopt globstar
globstar           off

In that case, ** behaves just like * and will match exactly 1 directory level.

$ ls spec/**/*_spec.rb
spec/models/user_spec.rb

To enable it, run

shopt -s globstar

The double asterisk will then expand to any number of directories:

$ ls spec/**/*_spec.rb
spec/world_spec.rb
spec/models/user_spec.rb
spec/models/user/authentication_spec.rb

To persist this setting, you need to run it everytime you open your shell, i.e. put it into your .bashrc (on Ubuntu there is even a commented-out line that you can just put back in).

If you changed only your bashrc, re-open your shell (or source ~/.bashrc).

Posted by Arne Hartherz to makandra dev (2017-01-10 11:40)