[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: DEL character treated specially when preceded by a backslash when us
From: |
Greg Wooledge |
Subject: |
Re: DEL character treated specially when preceded by a backslash when used in the RHS of the regex operator ([[ $'\177' =~ $'\\\177' ]]) |
Date: |
Fri, 17 Jan 2014 09:07:47 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Jan 17, 2014 at 08:53:07AM -0500, Chet Ramey wrote:
> On 1/17/14 8:01 AM, Greg Wooledge wrote:
> > I would expect [[ x =~ yx ]] to fail (return 1) every time.
>
> There is a question about the correct behavior when y == '\', since the
> backslash is special to pattern matching. When matching a pattern or a
> regexp, do you think x =~ \x should succeed, because the backslash acts
> as an escape?
OK, I see your point. Here are some more experiments:
imadev:~$ [[ x =~ \x ]] ; echo $?
0
imadev:~$ bs='\'
imadev:~$ [[ x =~ ${bs}x ]] ; echo $?
0
imadev:~$ [[ x =~ $'\\'x ]] ; echo $?
1
You get to decide which one(s) are bugs. ;-)
I chose the last one because $'...' is a form of quoting, and quoting
on the right hand side of =~ removes the specialness of things, which
muddies the waters greatly. The use of $'\\...' in the original question
led me to this, which may or may not be a tangential issue.
In order to remove that issue, I would have written the original question
this way:
imadev:~$ x=x; bs='\'; [[ $x = $bs$x ]] ; echo $?
0
imadev:~$ x=$'\177'; bs='\'; [[ $x = $bs$x ]] ; echo $?
1