Pattern Matching in case
Lesson 75 showed that a case branch starts with a pattern and that the first pattern matching the word wins. Almost every real script needs more than a plain word or a trailing *: it has to accept a whole family of values, such as any image extension, any option that starts with a dash, or any string made only of digits. This lesson looks closely at the pattern language itself. It covers bracket expressions, character classes, the way * treats slashes and dots, quoting inside patterns, and the extended patterns that Bash adds with the extglob option.
What a case Pattern Is
A case pattern is a shell pattern, the same wildcard language used to match file names (lesson 52). It is not a regular expression. The important point is that the pattern must match the entire word, from the first character to the last. The basic building blocks are:
| Element | Meaning |
|---|---|
* | any run of characters, including none |
? | exactly one character |
[abc] | one character from the listed set |
[a-f] | one character from a range |
[!abc] | one character that is not in the set |
[[:digit:]] | one character from a named class |
|