So, I’m leaning Bash scripting currently, and I’m a bit confused about the difference between pattern matching and file name expansion.
The Bash Reference manual reads:
After word splitting, unless the
-f' option has been set (see section 4.3.1 The Set Builtin), Bash scans each word for the characters*’,?', and[‘. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.
This to me suggests that the following should probably not do what we want:
if [[ $a == [cb]at* ]] ; then ...
In this case [cb]at* doesn’t expand to a list of files beginning cat or bat as the above quote suggests, but acts more like a very limited regular expression. Why? When do the characters *?[ act like a regular expression instead of expanding to matched files in the current directory?
bash interpret the tokens within the
[[ ... ]]differently. It’s a feature.