Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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.