[Top][All Lists]

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

Regex matching oddity (bug, or 'unexpected feature' or...?)

From: Linda Walsh
Subject: Regex matching oddity (bug, or 'unexpected feature' or...?)
Date: Thu, 28 May 2009 12:58:10 -0700
User-agent: Thunderbird (Windows/20090302)

Instead of checking if "$Var" was equal or not equal, I wanted to use
pattern matching.

Normally, for = or !=, I'd write:
        if [[ "$Var" = "4" ]]; then ...

But when I used regex pattern matching in the if, the spaces around the operator caused a failure in matching. I.e.:
        if [[ "$Var"=~"+([:digit:])" ]] ; then ...

        if [[ "$Var" =~ "+([:digit:])" ]] ; then ...
evaluates to 'FALSE', trace(-x) shows the eval as:
        + [[ 4 =~ \+\(\[:digit:]\) ]]
and inserting a space on only-one side of the operator yielded the error
        "conditional binary operator expected"
at the line of the expression.

Obviously, I can workaround my mis-comprehension and just proceed,
but I wanted to ask why, what I thought was "normal" syntax,
(i.e. args separated by spaces), didn't work.

bash --version:
GNU bash, version 3.2.39(1)-release (x86_64-suse-linux-gnu)


reply via email to

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