shell学习16:-eq,-ne,-gt,-lt,-ge,-le的意思

 解释如下:

-eq           //等于 (equal)
-ne           //不等于 (not equal)
-gt           //大于 (greater than)
-lt           //小于  (less than)
-ge           //大于等于 (great equal)
-le           //小于等于 (less equal)

 测试代码:

#!/bin/bash
#
t=10
echo "test1: -eq"
if [ $t -eq 10 ]
then
	echo "$t=10"
fi
echo "test2: -ne"
if [ $t -ne 0 ]
then
	echo "$t!=0"
fi
echo "test3: -gt"
if [ $t -gt 9 ]
then
	echo "$t>9"
fi
echo "test4: -lt"
if [ $t -lt 11 ]
then
	echo "$t<11"
fi
echo "test5: -ge"
if [ $t -ge 8 ]
then
	echo "$t>=8"
fi
echo "test6: -le"
if [ $t -le 12 ]
then
	echo "$t<=12"
fi
exit 0

测试结果:

gyz@debian:~/shelltest$ ./equl.sh 
test1: -eq
10=10
test2: -ne
10!=0
test3: -gt
10>9
test4: -lt
10<11
test5: -ge
10>=8
test6: -le
10<=12

 

你可能感兴趣的:(shell学习之路)