双园括号(( ... ))
:
<=
,,,,,,。<
>=
>
==
!=
单方括号[ ... ]
和双括号[[ ... ]]
:
-le
,,,,,,。-lt
-ge
-gt
-eq
-ne
示例 脚本
#!/usr/bin/bash
x=3
# Using (( ... )) for arithmetic comparison
if (( x <= 5 )); then
echo "x is less than or equal to 5"
fi
# Using [ ... ] for numeric comparison
if [ $x -le 5 ]; then
echo "x is less than or equal to 5"
fi
# Using [[ ... ]] for numeric comparison
if [[ $x -le 5 ]]; then
echo "x is less than or equal to 5"
fi
以下 , 单 双方括号 都可以
-eq 等于,如:if [ "$a" -eq "$b" ]
-ne 不等于,如:if [ "$a" -ne "$b" ]
-gt 大于,如:if [ "$a" -gt "$b" ]
-ge 大于等于,如:if [ "$a" -ge "$b" ]
-lt 小于,如:if [ "$a" -lt "$b" ]
-le 小于等于,如:if [ "$a" -le "$b" ]
以下 全部 需要圆双括号
< 小于(需要双括号),如:(("$a" < "$b"))
<= 小于等于(需要双括号),如:(("$a" <= "$b"))
> 大于(需要双括号),如:(("$a" > "$b"))
>= 大于等于(需要双括号),如:(("$a" >= "$b"))