bug-bash
[Top][All Lists]
Advanced

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

Re: bash-4.3.33 regexp bug


From: Eduardo A . Bustamante López
Subject: Re: bash-4.3.33 regexp bug
Date: Thu, 5 Mar 2015 08:51:17 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

On Thu, Mar 05, 2015 at 02:26:48PM +0000, Jason Vas Dias wrote:
> Good day list, Chet -
> 
> I think this is a bug:
> ( set -x ;  tab=$'\011';  s="some text: 1.2.3";
>   if [[ "$s" =~ ^some text:[\ $tab]+([0-9.]+) ]]; then
>     echo "${BASH_REMATCH[1]}";
>   fi
> )
> -bash: syntax error in conditional expression
> -bash: syntax error near `$tab]+([0-9.]+)'
> 
>From a quick glance, it does seem like a parsing bug, it should not break with
a syntax error.

Though, you can work-around this issue by doing the recommended approach to
regex matching: storing the regex in a variable.

|  address@hidden ~ % bash bug
|  + s='some text: 1.2.3'
|  + r='^some text:[       ]+([0-9.]+)'
|  + [[ some text: 1.2.3 =~ ^some text:[   ]+([0-9.]+) ]]
|  + echo 1.2.3
|  1.2.3
|  
|  address@hidden ~ % cat bug
|  #!/bin/bash
|  ( set -x ; s="some text: 1.2.3";
|    r=$'^some text:[ \t]+([0-9.]+)'
|    if [[ "$s" =~ $r ]]; then
|      echo "${BASH_REMATCH[1]}";
|    fi
|  )

See http://mywiki.wooledge.org/BashGuide/Patterns#Regular_Expressions-1 and
http://tiswww.case.edu/php/chet/bash/FAQ (E14).



reply via email to

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