bug-bash
[Top][All Lists]
Advanced

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

Re: Interpretation of escapes in expansions in pattern matching contexts


From: Chris F.A. Johnson
Subject: Re: Interpretation of escapes in expansions in pattern matching contexts
Date: Sat, 6 Apr 2013 21:59:00 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Sat, 6 Apr 2013, Chet Ramey wrote:

On 4/6/13 4:48 AM, Dan Douglas wrote:
I couldn't find anything obvious in POSIX that implies which interpretation is
correct. Assuming it's unspecified.

Bash (4.2.45) uniquely does interpret such escapes for [[, which makes me
think this test should say "no":

    x=\\x; if [[ x == $x ]]; then echo yes; else echo no; fi

bash: yes
ksh:  no
mksh: no
zsh:  no

However, ksh93 (AJM 93v- 2013-03-17) is unique in that it flips the result
depending on "[[ ]]" or "case..esac" (bug?), but otherwise it looks like a
fairly random spread:

    x=\\x; case x in $x) echo yes;; *) echo no; esac

These two cases should not be different.  They undergo the same expansions,
except that the conditional command adds quote removal, which doesn't
matter in this case.  In both cases, you ask the pattern matching code
whether or not the string `x' matches the pattern `\x'.

You invoke the same pattern matching code on the same patterns, why would
you not get the same answer?

  In bash, the expansion differs when in  [[ ... ]]:

$ x=\\x; if [[ x == $x ]]; then echo yes; else echo no; fi
yes
$ x=\\x; if [ x == $x ]; then echo yes; else echo no; fi
no

  But not in ksh93:

$ x=\\x; if [[ x == $x ]]; then echo yes; else echo no; fi
no
$ x=\\x; if [ x == $x ]; then echo yes; else echo no; fi
no



--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

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