bug-bash
[Top][All Lists]
Advanced

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

Re: Bug in bash regex: doesn't recognise the line start caret


From: DJ Mills
Subject: Re: Bug in bash regex: doesn't recognise the line start caret
Date: Fri, 4 Nov 2011 12:23:03 -0400

On Fri, Nov 4, 2011 at 4:31 AM, Graham North <graham@turbo-electric.com> wrote:
> Hi,
>
> There seems to be a bug in bash regex.
>
> It doesn't recognise the line start caret:
>
> --Commands:
> ONE="/fred"
> TWO="fred/"
> REGEX='^/'
> echo "$ONE $TWO $REGEX"
> [[ "$ONE" =~ "$REGEX" ]] && echo yes || echo no
> [[ "$TWO" =~ "$REGEX" ]] && echo yes || echo no
>
>
> --Result:
> /fred fred/ ^/
> no
> no
>
> Not sure how to proceed.
>
> Thanks
>
> Graham (0779 321 1967)
>
>
>
>

The regex must not be quoted.  [[ $one =~ $regex ]].

Also, as an aside, don't use all-caps variable names.  Those should
only be used for environment and internal shell variables (as in
internal to bash).



reply via email to

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