bug-bash
[Top][All Lists]
Advanced

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

Re: How to use [[ string =~ regexp ]]?


From: Chet Ramey
Subject: Re: How to use [[ string =~ regexp ]]?
Date: Sun, 21 May 2006 22:40:08 -0400
User-agent: Thunderbird 1.5.0.2 (Macintosh/20060308)

Bob Proulx wrote:
> Chet Ramey wrote:
>> Peter Volkov wrote:
>>> Please CC my email to answers as I'm not subscribed to the list.
>>> $ [[ "string" =~ "[a-z]" ]] && echo something
>>> something
>> ...
>> The real question is whether or not quoting the pattern should work as
>> it does with other [[ pattern matching operators, which is to quote any
>> characters special to the matching engine.  I think it should, for
>> consistency.
> 
> Could you give an example of how you think it should work?  (Just
> curious and trying to keep up.)

The documentation for [[ says this about the == and != operators,
which take patterns as the right-hand side:

        Any part of the pattern may be quoted to force it to
        be matched as a string.

It seems reasonable that quoting any part of the rhs to the =~
operator should cause it to behave in the same manner.

Since the arguments to [[ don't undergo any of the expansions that
require quoting to protect them, there's no reason for =~ to act
differently than the other operators that do pattern matching.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                       Live Strong.  No day but today.
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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