Take the 2-minute tour ×
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:

$ 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?

share|improve this question

1 Answer 1

up vote 3 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
matches
share|improve this answer

Your Answer

 
discard

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.