1.sed加正则表达式
[ -n "`echo $num1|sed 's/[0-9]//g'`" -o -n "`echo $num2|sed 's/[0-9]//g'`"]
判断:将两个数字用sed去掉 判断是否为空 。为空则是纯数字;不为空则不为纯数字
如果两个数字其中一个有字符,则此语句成立 返回值为1; 均为数字则返回值为 0 语句不成立
2.(1)变量的子串替换加正则表达式
判断:当去掉数字后,判断是否有非数字字符num=abc123[ -z "`echo "${num//[0-9]/}"`" ]&& echo 1||echo 0
(2)将num的非数字去掉,判断是否等于num本身,如果相等则是纯数字
[root@jason ~]# num=123
[root@jason ~]# [ -n "$num" -a "$num" = "${num//[^0-9]/}" ] && echo 1
1
[root@jason ~]# num=123a
[root@jason ~]# [ -n "$num" -a "$num" = "${num//[^0-9]/}" ] && echo 1||echo 0
0
3.expr计算
判断expr $1 + 0的返回值$?是否为0 ,返回0则是纯数字
[root@jason ~]# a=1
[root@jason ~]# expr $a + 0
1
[root@jason ~]# [ $? -eq 0 ] && echo int
int