shell if 语句

症状:shell中大于,大于等于,小于等于,lt,gt ,ne,ge,le 很对应。

应对方法:

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

  

-o 表示 逻辑“或”,查找/dev目录下类型为b(块设备)或c(字符设备)的设备文件。
跟shell的test判断表达式中的逻辑关系符一样:
-a 逻辑与And
-o 逻辑或Or

  

#!/bin/bash 
echo -n "please choose your score "
read R
if [ $R -lt 0 -o $R -gt 100 ]    
then 
	echo "not in [0,100]"
	exit
fi

G=`expr $R / 10`  #注意加上一些·· 才可以进行比较
case $G in
	9|10)
		echo "A"
	;;

    7|8)
		echo "B"
		;;
	6)
		echo "C"
		;;
	*)
		echo "not pass"
		;;
esac	

  

猜你喜欢

转载自www.cnblogs.com/jack-hzm/p/10201405.html