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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)