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: Stephane Chazelas
Subject: Re: bash-4.3.33 regexp bug
Date: Thu, 5 Mar 2015 17:07:44 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

2015-03-05 14:26:48 +0000, Jason Vas Dias:
> 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.]+)'
[...]

You forgot to quote the first space. Should be

  if [[ "$s" =~ ^some\ text:[\ $tab]+([0-9.]+) ]]; then

I'd use [[:blank:]] to match blanks though.

bash also supports \s, but that's more for [[:space:]] (so
includes vertical spacing like CR, LF), and you need to use an
intermediary variable:

r='^some text:\s+([0-9.]+)'
[[ $s =~ $r ]]

or use

shopt -s compat31
[[ $s =~ '^some text:\s+([0-9.]+)' ]]

or use zsh

in bash-3.2, the behaviour was changed (broken IMO) to match
ksh93's.

-- 
Stephane



reply via email to

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