Is there any bash command to do something similar to:
if [[ $string =~ $pattern ]]
but that it works with simple wild cards (?,*) and not complex regular expressions ??
More info:
I have a config file (a sort of .ini-like file) where each line is composed of a wild card pattern and some other data.
For any given input string that my script receives, I have to find the first line in the config file where the wild card pattern matches the input string and then return the rest of the data in that line.
It’s simple. I just need a way to match a string against wild card patterns and not RegExps since the patterns may contain dots, brackets, dashes, etc. and I don’t want those to be interpreted as special characters.
The
[ -z ${string/$pattern} ]trick has some pretty serious problems: if string is blank, it’ll match all possible patterns; if it contains spaces, the test command will parse it as part of an expression (trystring="x -o 1 -eq 1"for amusement). bash’s [[ expressions do glob-style wildcard matching natively with the == operator, so there’s no need for all these elaborate (and trouble-prone) tricks. Just use: