shell 脚本中的运算符 `-gt` 是什么意思?

Ser*_*io 9 shell shell-script test

嗨,我有这句话,我想知道它是什么意思。

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
Run Code Online (Sandbox Code Playgroud)

什么-gt意思?

gle*_*man 13

$ 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.
Run Code Online (Sandbox Code Playgroud)

  • @schily 相反:任何提供名为“help”(或“test”、“exit”或任何其他常见英语单词)的可执行文件的专有软件都会立即自我取消资格,因为他们可能没有想太多关于其他一些关键决策。 (2认同)

Kus*_*nda 13

-gt意思是“大于”。它用于比较整数以表示通常用>其他语言编写的不等式(在某些 shell 中,使用test实用程序 或 inside [ ... ]>比较两个字符串以进行字典排序,因此它与 具有非常不同的含义-gt)。

-gt该手册中记载的test[,或在你的shell的手册,如果这些内置的实用工具,如

n1 -gt n2

如果整数n1在代数上大于整数,则为真n2;否则为假。

(以上摘自有关test实用程序的 POSIX 标准文本

Fortran 还在其.GT.数字关系运算符中使用此缩写。

用于比较 shell 中整数 withtest或 in的其他相关运算符[ ... ]-ge("greater-than or equal"), -lt("less-than"), -le("less-than or equal"), -eq("equal") 和-ne("不相等”)。

有趣的是,所有的这些都是用Fortran相同的(.GT..GE..LT..LE..EQ..NE.)。