
こんにちは。この文章があるのですが、どういう意味なのか知りたいです。
if [[ -z "$1" ]]; then # --> this is if the value of the parameter $1 is zero
PASO=1
elif [[ "$1" -gt 1 ]] ; then # but i don't know what this flags mean? .."-gt"
LOG "[$(date +%T)] Parametros incorrectos"
exit 255
else
PASO=$1
fi
どういう-gt
意味?
答え1
-gt
は「より大きい」を意味します。これは、他の言語で通常記述される不等式の整数を比較するために使用されます>
(一部のシェルでは、test
内のユーティリティまたは を使用して[ ... ]
、>
辞書式順序で 2 つの文字列を比較するため、 とは意味が大きく異なります-gt
)。
-gt
test
またはのマニュアル[
、またはこれらが組み込みユーティリティの場合はシェルのマニュアルに記載されています。
n1 -gt n2
整数が
n1
整数より代数的に大きい場合は truen2
、それ以外の場合は false。
(上記はtest
ユーティリティに関するPOSIX標準テキスト)
.GT.
Fortran では、数値の関係演算子でもこの略語が使用されます。
シェル内の整数を withtest
または in で比較するためのその他の関連演算子は、("以上")、("以下")、("以下")、("等しい")、 ("等しくない")[ ... ]
です。-ge
-lt
-le
-eq
-ne
興味深いことに、全てこれらのうち、Fortranでは同じです ( .GT.
、、、、および) 。.GE.
.LT.
.LE.
.EQ.
.NE.
答え2
$ help test
test: test [expr]
Evaluate conditional expression.
...
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
-lt, -le, -gt, or -ge.
Arithmetic binary operators return true if ARG1 is equal, not-equal,
less-than, less-than-or-equal, greater-than, or greater-than-or-equal
than ARG2.
答え3
から始めるとhelp test
、演算子でサポートされている構文の POSIX サブセットのヘルプが表示されます[[
。
包括的なドキュメントはCONDITIONAL EXPRESSIONS
のセクションにありますman bash
。
具体的には:
Other operators:
...
arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
-lt, -le, -gt, or -ge.
Arithmetic binary operators return true if ARG1 is equal, not-equal,
less-than, less-than-or-equal, greater-than, or greater-than-or-equal
than ARG2.