[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Confused by =~ behavior with regards to quoting
From: |
Pierre Gaston |
Subject: |
Re: [Help-bash] Confused by =~ behavior with regards to quoting |
Date: |
Fri, 17 Oct 2014 15:24:56 +0300 |
On Fri, Oct 17, 2014 at 12:37 PM, Jean Delvare <address@hidden> wrote:
> Hi all,
>
> I'm am confused by the behavior of the =~ operator with regards to
> quoting, in particular the right hand side:
>
> $ echo $BASH_VERSION
> 4.2.47(1)-release
> $ [[ a =~ a ]] ; echo $?
> 0
> $ [[ a =~ ^a ]] ; echo $?
> 0
> $ [[ a =~ "a" ]] ; echo $?
> 0
> $ [[ a =~ "^a" ]] ; echo $?
> 1
>
> Can anyone explain that last failure to me? The third test suggests
> that quoting the right hand side is allowed, so why does the fourth
> test fail? Is this a bug?
>
> I see the same with bash 3.2.51(1)-release on SLED11 SP3, and with a
> self-built bash 4.3.30(1)-release, so it not specific to a version.
>
> Thanks,
> --
> Jean Delvare
> SUSE L3 Support
>
>
The relevant bit is "Any part of the pattern may be quoted to force it to
be matched as a string."
So, in quotes, the ^ is treated literally and has not special meaning.
(Note this was not the case in 3.1 - there is a shopt -s compat31 also)