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 16:19:55 -0400
User-agent: Thunderbird 1.5.0.2 (Macintosh/20060308)

Peter Volkov wrote:
> Hello.
> 
> Please CC my email to answers as I'm not subscribed to the list.
> 
> I have problems using =~ operator. I've tried to search for answer, but
> failed. I'm using GNU bash, version 3.1.17. Can anybody give me some
> examples of usage?
> 
> I really do not understand why
> 
> $ [[ "string" =~ "[a-z]" ]] && echo something
> something
> 
> echo me something. IIUC the regular expression [a-z] matches any single
> letter, so how string "string" matches one letter?
> 
> Seems that I missed the point, or did I encounter bug?

regexec(3) returns success for that pattern, so the [[ command succeeds.
I'm not sure why, unless it thinks it doesn't have to match the entire
string.

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.

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]