免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1523 | 回复: 2
打印 上一主题 下一主题

if 逻辑表达式 [复制链接]

smurf 该用户已被删除
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-30 18:19 |只看该作者 |倒序浏览
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
2 [报告]
发表于 2009-07-30 19:43 |只看该作者
[[ expression ]]
              Return a status of 0 or 1 depending on the evaluation of the conditional expression expression.  Expressions are composed of  the
              primaries  described  below  under CONDITIONAL EXPRESSIONS.  Word splitting and pathname expansion are not performed on the words
              between the [[ and ]]; tilde expansion, parameter and variable expansion, arithmetic  expansion,  command  substitution,  process
              substitution,  and quote removal are performed.  Conditional operators such as -f must be unquoted to be recognized as primaries.

              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.  If the shell option nocasematch is enabled, the match is performed without
              regard to the case of alphabetic characters.  The return value is 0 if the string matches (==) or does not match  (!=)  the  pat-
              tern, and 1 otherwise.  Any part of the pattern may be quoted to force it to be matched as a string.

              An additional binary operator, =~, is available, with the same precedence as == and !=.  When it is used, the string to the right
              of the operator is considered an extended regular expression and matched accordingly (as in regex(3)).  The return value is 0  if
              the  string  matches the pattern, and 1 otherwise.  If the regular expression is syntactically incorrect, the conditional expres-
              sion’s return value is 2.  If the shell option nocasematch is enabled, the match is performed  without  regard  to  the  case  of
              alphabetic  characters.   Substrings matched by parenthesized subexpressions within the regular expression are saved in the array
              variable BASH_REMATCH.  The element of BASH_REMATCH with index 0 is the portion of the string matching the entire regular expres-
              sion.  The element of BASH_REMATCH with index n is the portion of the string matching the nth parenthesized subexpression.

              Expressions may be combined using the following operators, listed in decreasing order of precedence:

              ( expression )
                     Returns the value of expression.  This may be used to override the normal precedence of operators.
              ! expression
                     True if expression is false.
              expression1 && expression2
                     True if both expression1 and expression2 are true.
              expression1 || expression2
                     True if either expression1 or expression2 is true.

              The  &&  and  || operators do not evaluate expression2 if the value of expression1 is sufficient to determine the return value of
              the entire conditional expression.

论坛徽章:
1
巨蟹座
日期:2014-06-04 13:33:30
3 [报告]
发表于 2009-07-30 19:59 |只看该作者
[]是shell内建的test,不是/usr/bin/test
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP