bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [[ ... =~ ... ]] is broken when RHS is quoted


From: Dave B
Subject: Re: [[ ... =~ ... ]] is broken when RHS is quoted
Date: Sun, 22 Jun 2008 18:01:08 +0200
User-agent: Thunderbird 2.0.0.14 (X11/20080529)

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

[Prev in Thread] Current Thread [Next in Thread]