The following code
number=1 if [[ $number =~ [0-9] ]] then echo matched fi
works. If I try to use quotes in the regex, however, it stops:
number=1 if [[ $number =~ '[0-9]' ]] then echo matched fi
I tried '\[0-9\]', too. What am I missing?
Funnily enough, bash advanced scripting guide suggests this should work.
Bash version 3.2.39.
It was changed between 3.1 and 3.2. Guess the advanced guide needs an update.
Sadly this’ll break existing quote using scripts unless you had the insight to store patterns in variables and use them instead of the regexes directly. Example below.