Linux --- Shell的if判断条件问题 (-lt和>的使用情况)

Shell的判断条件有两种写法:1.-lt(小于),-gt(大于),-le(小于等于),-ge(大于等于),-eq(等于),-ne(不等于)

l--less

g--great

t--than

e--equal

n--not

if [ $s -lt 0 ] || [ $s -gt 100 ]
then
        echo "number is out of range, 1-100"
        exit 1
fi

在shell中需要和 [x  x](中括号)搭配使用,另外,需要注意x的位置应该给空格

2.>,<,==,>=,<=

需要和((  )) 双小括号搭配使用

if (( $s < 60 ))
then
        tag=1
elif (( $s < 80 ))
then
        tag=2
else
        tag=3
fi

对初学者来说,容易混淆,马克一下.

扫描二维码关注公众号,回复: 4182318 查看本文章

猜你喜欢

转载自blog.csdn.net/Gino_tkzzz/article/details/83993532