我们如何比较 [00:00:10 和 00:00:22] 的时间格式?

How can we compare the time format such that [ 00:00:10 and 00:00:22 ]?

我有这样的程序执行时间 00:00:10, 00:30:23

问题是我如何将它们相互比较?

val1="00:00:10"
val2="00:30:23"

if [ "$val1" -gt "$val2" ]; then
    echo "bigger"
else
    echo "smaller"
fi

这给出了它们不是整数的错误。

因此,当我将不带 -gt 的代码更改为 > 它也不起作用..

你能告诉我如何比较我上面解释的时间格式吗?

非常感谢..

您可以改为使用 [[ "$val1" > "$val2" ]] 来比较日期:

─$ if [[ 00:00:10 > 00:30:23 ]]; then echo yes; else echo no; fi
no
─$ if [[ 00:00:10 < 00:30:23 ]]; then echo yes; else echo no; fi
yes