Alexis Huxley wrote:

> Description:
>       [[ ... =~ ... ]] is broken when RHS is quoted

AFAICT that seems to have changed from 3.2alpha. According to the changelog,
from version 3.2alpha, "Quoting the string argument to the [[ command's  =~
operator now forces string matching, as with the other pattern-matching
operators".

$ bash -c '[[ "^apple" =~ ^apple ]]; declare -p BASH_REMATCH'
declare -ar BASH_REMATCH='()'
$ bash -c '[[ "^apple" =~ "^apple" ]]; declare -p BASH_REMATCH'
declare -ar BASH_REMATCH='([0]="^apple")'

Spaces (and possibly other special chars) in the RHS should be escaped:

$ bash -c '[[ "apple banana" =~ ^apple\ banana ]]; declare -p BASH_REMATCH'
declare -ar BASH_REMATCH='([0]="apple banana")'
$ bash -c '[[ "apple banana" =~ ^(apple)\ (banana) ]]; declare -p BASH_REMATCH'
declare -ar BASH_REMATCH='([0]="apple banana" [1]="apple" [2]="banana")'

$ bash --version
GNU bash, version 3.2.33(1)-release (i686-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

-- 
D.

Reply via email to