On Wed, Aug 26, 2009 at 4:19 PM, Greg Wooledge <wool...@eeg.ccf.org> wrote:
> Assuming the first part was supposed to be var='"*"' ... > yup > > The bash command [[ \* = $var ]] returns true if $var contains a glob > pattern against which a literal asterisk * can be matched. (By the way, > you don't need the \ there. No glob expansion is done inside [[...]] so > you could use a plain * on the left hand side.) > > If $var contains \* then the match is successful. \* as a glob describes > a literal asterisk, which is what we're trying to match. > $ var='\*'; [[ * = $var ]]; echo $? > 0 > > If $var contains "*" (double quote, asterisk, double quote), then > the double quotes are considered part of the glob pattern. A bare > asterisk won't match that glob, because it doesn't have double quotes > attached to it. > > imadev:~$ var='"*"'; [[ * = $var ]]; echo $? > 1 > > It only matches double quote, asterisk, double quote: > > $ var='"*"'; [[ \"*\" = $var ]]; echo $? > 0 Thanks, I agree with that, I'm sorry I should have been more explicit, what was not clear to me was where this special role of the \ is explained, Because if you use literals [[ something = \* ]] is the same as [[ something = "*" ]] I found my explanation in the manual under "Pattern Matching": "A backslash escapes the following character; the escaping backslash is discarded when matching." PS, for Linda, http://mywiki.wooledge.org/BashFAQ/031 has more information about the differences between [[ and [