On 1/17/14, 9:07 AM, Greg Wooledge wrote: > 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. ;-)
The second. In the first case, the backslash disappears before we even hit the regexp matcher as an outcome of the word expansions. The second and third should be equivalent. I'm still working through it. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/