[Top][All Lists]

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

Re: Inconsistence when checking if a pattern is quoted or not for `==' a

From: Chet Ramey
Subject: Re: Inconsistence when checking if a pattern is quoted or not for `==' and `=~' in [[ ]]
Date: Thu, 17 Feb 2011 17:18:23 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: Gecko/20101207 Thunderbird/3.1.7

On 2/17/11 10:28 AM, Greg Wooledge wrote:
> On Thu, Feb 17, 2011 at 05:07:40PM +0200, Pierre Gaston wrote:
>> On Thu, Feb 17, 2011 at 4:56 PM, Clark J. Wang <address@hidden> wrote:
>>> The point is: ``Any part of the pattern may be quoted to force  it  to  be
>>> matched  as  a string.'' And backslash is one of bash's quoting chars.
>> aaah well the "it" in "force it" is the part, not the whole pattern. so if
>> you do \.. the first . is a litteral dot, the second one matches any char.
> I think you're all missing what Clark's question actually is.  Consider
> this:
> imadev:~$ cat <<\EOF
>> $PATH
>> EOF 
> The use of a backslash in front of one of the characters of the
> here-document's sentinel word is considered "quoting".  And because the
> sentinel word is "quoted", parameter expansions in the body are not done.
> Clark is asking why the use of a backslash before a character on the
> right-hand-side of =~ is not considered "quoting" the same way it is when
> doing it to a here-document's sentinel word.

How is it different?  Backslash removes any special meaning from the
following character.  When used in a pattern context, that means that
any backslash-quoted special matching character loses its special meaning,
and is matched as a literal character.  Quoting `a' and `.' in a regexp
does the same thing: forces them to be matched exactly as `a' and `.'.

Maybe if the man page had read "...to force the quoted portion to be
matched as a string" this could have been avoided.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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