Description of problem: '[' in regular pattern needs to be escaped twice '\\[' whereas in bash version 4.x it needs only one '\'. Other characters like ' ' needs only one '\'. Version-Release number of selected component (if applicable): bash-3.2-32.el5 How reproducible: 100% Steps to Reproduce: 1. [[ [test] =~ ^\[\ *test\ *\]\ *$ ]]; echo $? Actual results: 1 Expected results: 0 Additional info: Currently I need to use following on RHEL-5: [[ [test] =~ ^\\[\ *test\ *\\]\ *$ ]]; echo $?
I found an workaround which works on all bash versions consistently. Whis way accept both a="^\[\ *test\ *\]\ *$"; [[ [test] =~ $a ]]; echo $? and a="^\\[\ *test\ *\\]\ *$"; [[ [test] =~ $a ]]; echo $?
That's one of the diferencies between two versions. I can't do anything with it. Read FAQ of bash (/usr/share/doc/bash-4*/doc/FAQ) parts E14 and E15. In short, if you want to bash-4 to behave like bash-3 you should turn on compat31 shell option - shopt -s compat31