- 论坛徽章:
- 0
|
请问替代test语句的[ ]和[[ ]]表达式有什么区别啊
ksh对[..]和[[..]]的解释:
(( expression ))
The arithmetic expression expression is evaluated; equivalent to
let "expression". See Arithmetic Expressions and the let com-
mand below.
[[ expression ]]
Similar to the test and [ ... ] commands (described later), with
the following exceptions:
o Field splitting and file name generation are not per-
formed on arguments.
o The -a (and) and -o (or) operators are replaced with &&
and ||, respectively.
o Operators (e.g., -f, =, !, etc.) must be unquoted.
o The second operand of != and = expressions are patterns
(e.g., the comparison in
[[ foobar = f*r ]]
succeeds).
o There are two additional binary operators: < and > which
return true if their first string operand is less than,
or greater than, their second string operand, respec-
tively.
o The single argument form of test, which tests if the
argument has non-zero length, is not valid - explicit
operators must be always be used, e.g., instead of
[ str ]
use
[[ -n str ]]
o Parameter, command and arithmetic substitutions are per-
formed as expressions are evaluated and lazy expression
evaluation is used for the && and || operators. This
means that in the statement
[[ -r foo && $(< foo) = b*r ]]
the $(< foo) is evaluated if and only if the file foo
exists and is readable. |
|