Bug 652211 - bash: '^' escaping breaks regex compare using =~
Summary: bash: '^' escaping breaks regex compare using =~
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: bash
Version: 13
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
Assignee: Roman Rakus
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-11-11 11:48 UTC by Tomas Hoger
Modified: 2014-01-13 00:13 UTC (History)
3 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2010-11-11 12:02:23 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Tomas Hoger 2010-11-11 11:48:31 UTC
Description of problem:
bash 4.1 seems to have changed the way '^' character is escaped in the strings, which breaks regex compare with '^' used to match start of the line.

Following prints 'match' when testing with various bash versions (EL4, EL5, F12):

var='foo' ; if [[ "$var" =~ '^f' ]] ; then echo 'match'; else echo 'no match'; fi

bash 4.1 reports 'no match' however.  Running with 'set -x' shows:

older bash versions:

+ var=foo
+ [[ foo =~ ^f ]]
+ echo match

bash 4.1:

+ var=foo
+ [[ foo =~ \^f ]]
+ echo 'no match'


Version-Release number of selected component (if applicable):
bash-4.1.7-1.fc13


Additional info:

This seems to work as a workaround: if [[ "$var" =~ ^'f' ]]

Comment 1 Roman Rakus 2010-11-11 12:02:23 UTC
Please take a look in bash's man page, section [[ expression ]]:
<snip>
Any part of the pattern may be quoted to force it to be matched as a string.

Older bashes work incorrectly, but it will not be fixed, because it will cause many scripts to stop working.


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