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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/