bug-bash
[Top][All Lists]
Advanced

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

Re: variable containing syntax error in conditional expression reports n


From: Chet Ramey
Subject: Re: variable containing syntax error in conditional expression reports no diagnostics
Date: Wed, 24 Feb 2016 14:09:22 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.6.0

On 2/24/16 9:13 AM, g.branden.robinson@gmail.com 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    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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