bug-bash
[Top][All Lists]
Advanced

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

Re: manpage note? weird strings that appear to be equal but create haywi


From: Linda Walsh
Subject: Re: manpage note? weird strings that appear to be equal but create haywire comparisons?
Date: Tue, 01 Sep 2009 14:48:08 -0700
User-agent: Thunderbird 2.0.0.22 (Windows/20090605)

Chet Ramey wrote:
Note that [[ and [ return different results when the vars are unquoted.

Yes.  There are two differences.

First, the operands in [[ do not undergo all word expansions.  The
arguments to [, since it's a builtin, do.  That doesn't really matter
to this example, but it's worth noting.

Second, the = and != operators in [[ perform pattern matching (= is
the same as ==).  You have to quote the rhs to force string matching.

In pattern matching, the backslash has a special meaning: it quotes the
next character.
---
 That makes sense -- but I was attributing it to the backslash being
within double quotes vs. single quotes, paralleling the expansion
of variables.  *sigh*

 So when $v is unquoted, the pattern matcher treats the
pairs of backslashes in $v as one backslash quoting another, and the
strings match.  When using [, bash does straight string comparison, and
the strings are not identical.
---
 That, I did not know. I thought it had to do with whether or
not you enclosed the string in single quotes or double quotes there,
too...

 I think I'm getting string rules from various languages confused at
times...*sigh*







reply via email to

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