shell脚本if中判断大于、小于、等于、不等于的符号

在shell中有时候会用到对数字进行判断的场景,尤其在写脚本判断参数的时候,以下有几个命令需要记住

  • 大于 -gt (greater than)
  • 小于 -lt (less than)
  • 大于或等于 -ge (greater than or equal)
  • 小于或等于 -le (less than or equal)
  • 不相等 -ne (not equal)
  • 相等 -eq (equal)

示例

echo $#
#参数要大于2个 否则退出,这个用于参数判断
if [ $# -gt 2 ]
then
	echo  "missing argument(s)"
	exit 1
fi

你可能感兴趣的:(Shell,安全)