man bash
:
[[ 式 ]]
[...] 式は、以下の条件式で説明するプライマリで構成されます。単語の分割とパス名の展開は、[[ と ]] の間の単語に対しては実行されません。
[...] == および != 演算子が使用されている場合、演算子の右側の文字列はパターンと見なされ、以下のパターン マッチングで説明するルールに従ってマッチングされます。
セクション全体では、シングルの場合は=
言及されていません。
条件式
[...]
string1 == string2
string1 = string2
文字列が等しい場合は True です。= は、POSIX 準拠の test コマンドで使用する必要があります。
この説明から私が予想するのは
[[ a = $cmpstring ]]
等しい文字列をチェックし、
[[ a == $cmpstring ]]
パターンの一致をチェックします。しかし、そうではありません:
> [[ a == ? ]]; echo $?
0
> [[ a = ? ]]; echo $?
0
> [[ a == "?" ]]; echo $?
1
私が何かを誤解しているのでしょうか、それとも bash のマニュアルページで言及し忘れているだけなのでしょうか=
?
答え1
=
==
内部の場合と同じです[[...]]
。最近のman
ページのSHELL GRAMMAR
>>Compound Commands
の下によると[[ expression ]]
:
The = operator is equivalent to ==
さらに下にはCONDITIONAL EXPRESSIONS
、
string1 == string2
string1 = string2
True if the strings are equal. = should be used with the test command
for POSIX conformance. When used with the [[ command, this performs pattern
matching as described above (Compound Commands).
bash info
ページ: