Skip to content

Instantly share code, notes, and snippets.

@nuclearglow
Forked from reggi/glob-up-and-running.md
Created August 16, 2018 09:12
Show Gist options
  • Save nuclearglow/d3d98df14358bf206e5aac40a921e282 to your computer and use it in GitHub Desktop.
Save nuclearglow/d3d98df14358bf206e5aac40a921e282 to your computer and use it in GitHub Desktop.
A tutorial on how to get started using glob patterns in your terminal. #writing

Glob Up and Running

To test a glob pattern go over to globtester and play around with creating your own file structure online, it's super easy to get started that way.

If you want to test out a glob pattern in the terminal use echo followed by the pattern, for instance.

echo **/*.js

If I run this within a directory with this structure.

.
├── hello
│   └── index.js
├── index.js
└── test.sh

I'll get back the following if you're running bash 4 with globstar enabled.

hello/index.js index.js

If you're running an older version of bash or globstar is not enabled. You might just return this.

hello/index.js

Check if you can enable glob support, run this command.

shopt -s globstar

If nothing happens your good, you can now run free and glob till your hearts content`. If you get an error that looks something like this then it may be time for you to update bash.

bash: shopt: globstar: invalid shell option name

Updating bash

Use brew to install bash, if you don't have it grab it here.

First off it's always a good sanity-check to see what version of bash your running before you start.

bash --version

Install bash with this command

brew update && brew install bash

This line will append the /etc/shells file with the new shell path.

sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'

Then your going to want to change to the new shell.

chsh -s /usr/local/bin/bash 

Now you have to quit the terminal and open it back up again. If you check the version it should show something updated.

bash --version

To enable glob support run the following.

shopt -s globstar

Additional Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment