test 3 -lt 6unix 端末にコマンドへの出力がないのはなぜですか? テスト出力を 0 または 1 にするべきではありませんか?
私は男のテストをしました、そしてそれは言います
EXPRESSION によって決定されたステータスで終了します
The exit status is not printed, it is just returned. You can test it in if or while, for example
if test 3 -lt 6 ; then
echo ok
else
echo not ok
fi
Moreover, the exit code of the last expression is kept in $?:
test 3 -lt 6; echo $?
test returns an exit status, which is the one that indicates if the test was succesfull. You can get it by reading $? right after executing test or you can use it directly in a control structure, for example:
if test 3 -lt 6
do echo "everything is aaaaalright"
else echo "whaaat?"
fi
シェル内のすべてtestのコマンドには、だけでなく戻り値があります。戻り値はかなり印刷されます。たとえば、ifまたはステートメントを使用して直接テストするか、またはwhileを使用したショートカットで使用します。場合によっては、戻り値を格納することがあります。これは、変数でも使用できます。&&||?
コマンドはtestかなり古いです。あなたがタグを付けたので、あなたはbash使用を検討したいかもしれません
if (( 3 < 6 )); then
算術テストの場合、または
if [[ $name == "Fred Bloggs" ]] ; then
テキストまたはパターンテスト用。
これらは一般的に直感的でエラーが発生しにくいです。のようtestに、(( ))は[[ ]]それ自体がコマンドであり、またはなしで使用できifますwhile。trueの場合は0(成功)を返し、falseの場合は1(失敗)を返します。
ちなみに、あなたがするとき、man testあなたは実際にtestプログラムのドキュメントを見ています。man bashまたはを使用した方がよい場合がありますhelp test。