Bash globbing and quoting.
Wildcards never reach the command — the shell expands them first. Watch what gets rewritten, and learn the three quoting styles that stop the shell from rewriting things you didn't mean it to.
Bash globbing and quoting animated tutorial. Shell pattern matching with wildcards, brace expansion, recursive globstar, and the three styles of quoting (single, double, backslash). Covers RHCSA EX200 shell objectives.Two of the most-misunderstood Bash features. Watch each example show what you typed, what the shell expanded it to, and what the command finally saw.
- ·Comfortable running basic commands (ls, cp, mv, rm)
- ·Know how to set a variable (FOO=bar) and reference it ($FOO)
- ·Helpful but not required: read the Command Line Essentials lesson first
Predict what the shell expands a pattern to before pressing Enter. Choose the right quoting style for each situation.
pace: 10 minutes
Globs: the shell rewrites your command before it runs
A glob (also called a wildcard) is a pattern the shell matches against existing filenames. The key idea: the shell expands the pattern into a list of real filenames before the command ever sees it. `*` matches zero or more characters (except a leading dot). `?` matches exactly one character.
The command never sees your * or $VAR. The shell rewrites the line first, then runs the result. Globs are matched against existing filenames; braces are pure text substitution; quoting suppresses one or more of the rewrite steps. When something behaves strangely, ask "what is the shell handing to the command?" — that's the line you actually ran.
$*$?$[abc]$[a-z]$[!abc] / [^abc]$**${a,b,c}${1..10} / {01..10}$'literal'$"$preserved"$\$$shopt -s dotglob$shopt -s nullglob$shopt -s globstar$shopt -s nocaseglob$set -f / set +fYour home directory contains .bashrc, .vimrc, notes.txt, and Documents/. What does `ls *` print?
How is `{a,b,c}` different from `[abc]`?
Which one of these prints your username, and which prints the literal string `$USER`?
Why is `for f in *.txt; do cp $f backup/; done` buggy when a filename contains a space?
These aren't graded — they're just for active recall, which is what actually makes the lesson stick.
Try the Bash Command Challenge
Several challenges hinge on getting the glob or the quoting right. Reading is one thing — typing it yourself and seeing the result is what cements the rules.