echo '評価結果が true の場合は終了ステータスが 0'
test ok
echo "test ok : \$?=$?"
test ''
echo "test '' : \$?=$?"
test ! ok
echo "test ! ok : \$?=$?"
test ! ''
echo "test ! '' : \$?=$?"
stdoutcode
test ok -a ok
echo "ok -a ok : \$?=$?"
test ok -a ''
echo "ok -a '' : \$?=$?"
test '' -a ok
echo "'' -a ok : \$?=$?"
test '' -a ''
echo "'' -a '' : \$?=$?"
stdoutcode
test ok -o ok
echo "ok -o ok : \$?=$?"
test ok -o ''
echo "ok -o '' : \$?=$?"
test '' -o ok
echo "'' -o ok : \$?=$?"
test '' -o ''
echo "'' -o '' : \$?=$?"
stdout
-a と -o 演算子は非推奨と test コマンドの man ドキュメントに記載があります。
NOTE:Binary -a and -o are inherently ambiguous.Use 'test EXPR1 && test EXPR2' or 'test EXPR1 || test EXPR2' instead.
code
# -a 演算子は非推奨のため && の使用が推奨
test ok && test ok
echo "test ok && test ok : $?"
test ok && test ''
echo "test ok && test '' : $?"
test '' && test ok
echo "test '' && test ok : $?"
test '' && test ''
echo "test '' && test '' : $?"
stdoutcode
# -o 演算子は非推奨のため || の使用が推奨
test ok || test ok
echo "test ok || test ok : $?"
test ok || test ''
echo "test ok || test '' : $?"
test '' || test ok
echo "test '' || test ok : $?"
test '' || test ''
echo "test '' || test '' : $?"
stdout
test ~ 文字列の演算子
条件
説明
-n STRING
STRING の文字数が 0 ではない
-z STRING
STRING の文字数が 0 である
STRING1 = STRING2
STRING1 と STRING2 が等しい
STRING1 == STRING2
STRING1 と STRING2 が等しい
STRING1 != STRING2
STRING1 と STRING2 が等しくない
STRING1 < STRING2
STRING1 が STRING2 より辞書順で前にある
STRING1 > STRING2
STRING1 が STRING2 より辞書順で後にある
code
test -n ''
echo "test -n '' : \$?=$?"
test -n ok
echo "test -n ok : \$?=$?"
test -z ''
echo "test -z '' : \$?=$?"
test -z ok
echo "test -z ok : \$?=$?"
stdoutcode
test '' = ''
echo "test '' = '' : \$?=$?"
test '' = ok
echo "test '' = ok : \$?=$?"
test '' = 'ok'
echo "test '' = 'ok' : \$?=$?"
test ok = ok
echo "test ok = ok : \$?=$?"
stdoutcode
test '' == ''
echo "test '' == '' : \$?=$?"
test '' == ok
echo "test '' == ok : \$?=$?"
test '' == 'ok'
echo "test '' == 'ok' : \$?=$?"
test ok == ok
echo "test ok == ok : \$?=$?"
stdoutcode
test '' != ''
echo "test '' != '' : \$?=$?"
test '' != ok
echo "test '' != ok : \$?=$?"
test ok != ok
echo "test ok != ok : \$?=$?"
test ok != 'ok'
echo "test ok != 'ok' : \$?=$?"
stdoutcode
test A \< B
echo "test A <\ B : \$?=$?"
test B \< A
echo "test B \< A : \$?=$?"
test A \< A
echo "test A \< A : \$?=$?"
test \' \< ''
echo "test \' \< '' : \$?=$?"
test \' \< A
echo "test \' \< A : \$?=$?"
stdoutcode
test A \> B
echo "test A \> B : \$?=$?"
test B \> A
echo "test B \> A : \$?=$?"
test A \> A
echo "test A \> A : \$?=$?"
test \' \> ''
echo "test \' \> '' : \$?=$?"
test \' \> A
echo "test \' \> A : \$?=$?"