bug-bash
[Top][All Lists]
Advanced

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

Re: ksh style [[ conditional does not match patterns


From: Chet Ramey
Subject: Re: ksh style [[ conditional does not match patterns
Date: Thu, 08 Dec 2005 21:39:55 -0500
User-agent: Thunderbird 1.5 (Macintosh/20051025)

Michael Wardle wrote:
> In the SHELL GRAMMAR section of the bash man page, the [[ expression ]]
> syntax is described:
> 
>     When the == and != operators are used, the string to the right of
> the operator is
>     considered a pattern and matched according to the rules described below
>     under Pattern Matching.
> 
> The Pattern Matching subsection describes the familiar file name
> globbing syntax:
> 
>     *      Matches any string, including the null string.
>     ?      Matches any single character.
>     etc.
> 
> Yet when I attempt a simple match, it doesn't work:
> 
>     bash-3.00$ [[ "foo" == "foo" ]]
>     bash-3.00$ echo $?
>     0
>     bash-3.00$ [[ "foo" == "fo?" ]]
>     bash-3.00$ echo $?
>     1
> 
> (I expect the second command to return 0 exit status as well, since the
> question mark should match the single "o" character at position 3 in
> "foo".)
> 
> Am I doing something wrong?

You didn't read far enough in the man page.  Later on in the description
of `[[' is the following:

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

Quoting the pattern forces string comparison.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live Strong.
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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