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