Bug 854233 - regular expression evaluation differs from RHEL-6&7 bash
regular expression evaluation differs from RHEL-6&7 bash
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: bash (Show other bugs)
5.8
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Roman Rakus
BaseOS QE - Apps
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-04 09:02 EDT by Dalibor Pospíšil
Modified: 2014-01-12 19:14 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-09-04 09:30:37 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Dalibor Pospíšil 2012-09-04 09:02:16 EDT
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 $?
Comment 1 Dalibor Pospíšil 2012-09-04 09:10:02 EDT
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 $?
Comment 2 Roman Rakus 2012-09-04 09:30:37 EDT
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

Note You need to log in before you can comment on or make changes to this bug.