shell 脚本中怎么比较两个数的大小
在 shell 脚本中,可以使用 test 或者方括号来比较两个数的大小,例如:
a=10
b=20
# 判断 a 是否小于 b
if [ $a -lt $b ]; then
echo "a is smaller than b"
fi
# 判断 a 是否大于等于 b
if test $a -ge $b; then
echo "a is greater than or equal to b"
fi
其中,-lt 表示小于,-ge 表示大于等于。还有其他的比较运算符,如 -eq 表示等于,-ne 表示不等于,-gt 表示大于,-le 表示小于等于等等。需要根据具体情况选择合适的比较运算符。
原文地址: https://www.cveoy.top/t/topic/fnrr 著作权归作者所有。请勿转载和采集!