
您好,我有這句話,我想知道這是什麼意思。
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
意思是「大於」。它用於比較整數的不等式,這通常>
用其他語言編寫(在某些 shell 中,使用test
實用程式 or inside[ ... ]
比較>
兩個字串的字典順序,因此它與 具有非常不同的含義-gt
)。
-gt
test
記錄在或的手冊中[
,或記錄在您的 shell 手冊中(如果這些是內建實用程式),如
n1 -gt n2
若該整數
n1
在代數上大於該整數,則為 Truen2
;否則為假。
(以上摘自test
有關該實用程式的POSIX 標準文本)
Fortran 也在其.GT.
數位關係運算子中使用此縮寫。
在 shell 中比較整數的其他相關運算子test
有[ ... ]
( -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.