Red Hat Bugzilla – Bug 854233
regular expression evaluation differs from RHEL-6&7 bash
Last modified: 2014-01-12 19:14:46 EST
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):
Steps to Reproduce:
1. [[ [test] =~ ^\[\ *test\ *\]\ *$ ]]; echo $?
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 $?
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