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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)