次の正確な違いは何ですか:
if [ $? -ne 0 ];
と
if [[ $? -ne 0 ]];
ここで述べたように:
とは逆に
[
、[[
変数値の単語分割を防ぎます。したがって、 ifVAR="var with spaces"
、テストで二重引用符を使用する必要はありません$VAR
- 引用符を使用することは依然として良い習慣です。また、[[
パス名の展開を防止するため、ワイルドカードを含むリテラル文字列はファイル名に展開されません。を使用して[[
、右側の文字列をシェル glob パターンとして解釈し、左側の値と照合します。==
!=
[[ "value" == val* ]]
なにもない。ただし、[[
...]]
構文は、条件式で実行できる他のいくつかのことを紹介します。からhelp [[
:
Returns a status of 0 or 1 depending on the evaluation of the conditional
expression EXPRESSION. Expressions are composed of the same primaries used
by the `test' builtin, and may be combined using the following operators:
( EXPRESSION ) Returns the value of EXPRESSION
! EXPRESSION True if EXPRESSION is false; else false
EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false
When the `==' and `!=' operators are used, the string to the right of
the operator is used as a pattern and pattern matching is performed.
When the `=~' operator is used, the string to the right of the operator
is matched as a regular expression.