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