Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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


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

But Bash 3.0 is:


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

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

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.