Pattern Dispatch With case
Match glob patterns and run the matching branch in a script.
Use case "$arg" in *.tar.gz) ...;; *.md) ...;; esac to dispatch on patterns.
01Command
Command
$ case "$1" in *.tar.gz) echo archive;; *.md) echo docs;; *) echo other;; esac02What it does
case supports glob patterns such as *.tar.gz directly, which makes extension and argument dispatch concise and readable, without regex libraries. It is a standard shell construct for CLI tools.
03Risk
!Warning: Patterns are globs, not regex; . does not need escaping but regex quantifiers will not work.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- bash.1.en.html manual pageEvidence: The bash manual page documents case.
Last verified: 2026-10-13 · Category: Developer