6

Upgraded to Bash4 and found that it is not matching regexes:

$ echo $BASH_VERSION
4.1.2(1)-release

$ [[ "20110228" =~ "^[0-9]{8}$" ]] && echo matches

But Bash 3.0 is:

$ echo $BASH_VERSION
3.00.16(1)-release

$ [[ "20110228" =~ "^[0-9]{8}$" ]] && echo matches
matches

Why might this be? Have I not installed it correctly?

1 Answer 1

8

Check this answer on SO. Since you are using 3.00 version of bash 3, it might regard your problem. Shortly, starting from 3.2 version, quoting the string argument to the [[ command's =~ operator forces string matching, so the correct pattern for bash 4 should be:

$ [[ "20110228" =~ ^[0-9]{8}$ ]] && echo matches
matches

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .