测试表达式==左边的模式如何使用?

测试表达式==左边的模式如何使用?

复制内容到剪贴板
代码:
#!/bin/bash
# $Id: app.sh 314274 2004-05-24 21:04:46Z geiseri $
# test_bash - Copyright (C) 2008 apple User,,, <apple@apple>


gender="female"

echo "$gender"

if  test "$gender" == "female"
then echo "true"
else echo "fasle"
fi

#why is the result is false
if  test "$gender" == "f*"
then echo "true"
else echo "fasle"
fi
测试表达式==左边的模式如何使用?      
[[ ]] 里面是支持 == 的, 没听说 test 支持这种用法       
刚看了下文档test的格式是这样,你试下
test string = string
test "$gender" = "female"      
引用:
原帖由 dearvoid 于 2008-10-24 09:32 发表
[[ ]] 里面是支持 == 的, 没听说 test 支持这种用法
双引号怎么回事?双引号应该没有什么影响的
复制内容到剪贴板
代码:
gender="female"

echo "$gender"

##echo fasle
if [[ $gender == "f*" ]]
then echo "true"
else echo "fasle"
fi

##echo true
if [[ $gender == f* ]]
then echo "true"
else echo "fasle"
fi
      
== 右边的 pattern 加上双引号之后, == 做的是简单的字符串比较操作而不是 pattern matching 了, 跟 = 效果一样 这种行为的确让人很困惑

bash manual 里面是这么说的:
引用:
Any part of the pattern may be quoted to force it to be matched as a string.
      
看来bash指南的例子错了。

终于找到了原话
引用:
When the == and != operators are used the string to the right of the operator is considered a pattern and matched according to the rules described below under Pattern Matching. The return value is 0 if the string matches or does not match the pattern, respectively, and 1 otherwise.Any part of the pattern may be quoted to force it to be matched as string.
      
这里的模式肯定不是正则表达式,

这个模式是啥,基本模式?

这个模式和grep 的选项相关吗?
Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression (ERE)
  -F, --fixed-strings       PATTERN is a set of newline-separated fixed strings
  -G, --basic-regexp        PATTERN is a basic regular expression (BRE)
  -P, --perl-regexp         PATTERN is a Perl regular expression
  -e, --regexp=PATTERN      use PATTERN for matching
  -f, --file=FILE           obtain PATTERN from FILE
  -i, --ignore-case         ignore case distinctions
  -w, --word-regexp         force PATTERN to match only whole words
  -x, --line-regexp         force PATTERN to match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline      
这里说的是 glob style 的 pattern, 也就是平时我们所熟悉的文件通配符风格的那种