Pcornel
Linux · Shell & Bash

Globbing

Cheat sheet · https://pcornel.dk/topic.php?topic=2683

Back to the Topic

Answer

Globbing is filename pattern matching by the shell: * matches any string, ? one character, [abc] a set, and ** (with globstar) any depth. The shell replaces the pattern with matching names before running the command.

Remember

No match → Bash passes the pattern literally (unless nullglob is set), so rm *.log with no logs tries to delete a file called *.log. Globs do not match hidden files unless dotglob is set. Quote patterns you want passed to a program (find -name '*.log').

First checks

  • bash -x script.sh — trace each expanded command
  • bash -n script.sh — syntax check only
  • shellcheck script.sh — common bugs and quoting problems
  • echo $? — exit code of the last command

Verify in this order

pattern on the command line → shell matches names in the directory → replaced by sorted matches (or left literal) → command runs

Where it usually breaks

First mismatch in persistent intent → provider/parser/generator → kernel/userspace runtime → dependency/security context → logs/counters → consumer-visible read-back; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2683

Confirmation

Confirm action

Continue?