On 2/24/16 9:13 AM, [email protected] wrote:
> Bash Version: 4.3
> Patch Level: 30
> Release Status: release
>
> Description:
> I get a [[ ]] test failure with no error diagnostic, tricking me
> into thinking the test legitimately failed when the culprit was
> really a bad regex.
>
> Repeat-By:
> Constrast:
>
> $ [[ foo =~ ) ]] && echo match || echo no match
> bash: syntax error in conditional expression: unexpected token `)'
> bash: syntax error near `)'
This is a legitimate syntax error. `)' is an unquoted shell metacharacter
appearing in a place where that operator is invalid.
> $ REGEX=')'
> $ $ [[ foo =~ $REGEX ]] && echo match || echo no match
> no match
This parses successfully and gets passed to the system's C library regexp
function. Bash doesn't perform validity checks on regexp patterns, and
there's no reason it should.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/