#1.组合语法判断1: [ -n "`echo $num|sed 's/[0-9]//g`" -a -n "`echo $2|sed 's/[0-9]//g'`"] &&\echo”两个参数都必须为数字”&& exit 1#2.组合语法判断2:[ -n "`echo $num|sed ' s/[0-9]//g`" -a -n "`echo $2|sed 's/[0-9]//g`"] &&{echo”两个参数都必须为数字”exit 1 }#3.单个判断语法:
[ -n "`echo $1|sed 's/[0-9]//g`"] 8& echo“第一个参数必须为数字”&& exit 1
[ -n "`echo $2Ised 's/[0-9//g`" && echo ”第二个参数必须为数字”8& exit 1#4.普通变量判断:
[ -n "`echo $num sed 's/[0-9]//g'`" ] && echo”第二个参数必须为数字”& exit 1#条件表达式,大括号的用法:
[ -n "`echo $num|sed' s/[0-9]//g'`" ] &&{
echo“第二个参数必须为数字”
exit 1
]#5.用变量的字串替换正则表达式num=test[ -z "`echo "${nun//[0-9]/}"`"] &&echo 1||echo 0#6.变量的子串替换加正则表达式(特殊判断思路)。#如果num长度不为0,并且把num中的非数字部分删除,然后看结果是不是等于num本身,如果两者都成立就 #是数字。。-n "$num" #如果num长度不为0表达式。"$num" ="${num//[ 0-9]/}"#把mum中的非数字部分删除,然后看结果是不是等于mum本身,如果两者 #都成立就是数字。。#完整表达式[ -n "$num" -a "$num” = "${num//[^0-9]}/"]& echo "it is num"#7.expr计算
expr $1 + 0 >/dev/null 2>&1[$? -eq 0] && echo int