Bug 854233 - regular expression evaluation differs from RHEL-6&7 bash
Summary: regular expression evaluation differs from RHEL-6&7 bash
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: bash
Version: 5.8
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Roman Rakus
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-09-04 13:02 UTC by Dalibor Pospíšil
Modified: 2014-01-13 00:14 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-09-04 13:30:37 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Dalibor Pospíšil 2012-09-04 13:02:16 UTC
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 13:10:02 UTC
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 13:30:37 UTC
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.