From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7205 invoked by alias); 18 May 2015 03:07:52 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35175 Received: (qmail 15933 invoked from network); 18 May 2015 03:07:48 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Message-ID: <5559577C.1060906@inlv.org> Date: Mon, 18 May 2015 04:07:40 +0100 From: Martijn Dekker User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: Pattern matching: backslash escaping not active in pattern passed from variable Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Peter Stephenson's patch for case pattern matching applied cleanly against the latest git code and is working perfectly. Many thanks. There is another snag I've found in pattern matching, which seems to have survived this patch: backslash escaping does not seem match the standard if a glob pattern is passed from a variable or parameter. The standard says: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13_01 > A character shall escape the following character. The > escaping shall be discarded. This works correctly with a literal pattern: case abc in ( a\bc ) echo yes ;; ( * ) echo no ;; esac Got expected output: yes But it does *not* work correctly if the pattern is in a variable or parameter: glob='a\bc' case abc in ( $glob ) echo yes ;; ( * ) echo no ;; esac Expected output: yes (produced by bash, ksh93, dash) Got output: no (produced by zsh, mksh, ash) To be fair, existing implementations seem wildly inconsistent here, so perhaps I'm misreading something. In any case, the inconsistency is unfortunate. I like to use this simple function so I can write something like: if match "$somestuff" '*stuff*'; then [...] match() { case "$1" in ( $2 ) return 0 ;; esac return 1 } But the inconsistent handling of backslash escaping in glob patterns passed from variables or parameters makes it impossible to portably match a literal '*' or '?' using a method like this. mksh and ash never match a literal escaped \* and \?; oddly enough, zsh does, but does not match a (redundantly) escaped alphanumeric character. In any case, I would expect backslash escaping to work the same way whether the glob pattern is passed from a variable or parameter or not. Thanks, - Martijn