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: Chet Ramey
Subject: Re: bash-4.3.33 regexp bug
Date: Fri, 06 Mar 2015 11:38:51 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

On 3/5/15 9:26 AM, 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.]+)'
> 
> Do you agree ?

No.

This is a conditional command that looks like

        [[ "$s" =~ ^some garbage ]]

(four tokens).

When bash tries to make sense of the stuff after the space between
`^some' and `text', it can't find any operators that make sense in
that context -- or the closing `]]' -- and reports a syntax error.

The parser still has to tokenize the words in a conditional command,
and an unescaped space separates words.  If you escape that space, the
regular expression should match like you want.  It does in my testing.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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