如题所述
方法一、测试相加是否成功
expr $a+0 &>/dev/null
RETVAL=$?
test $RETVAL -eq 0 {echo "number"
exit 1
}
方法二、将数字全部用空格代替
[ -n "`echo $1|sed 's/[0-9]//g'`" ]&& { echo ...}
方法三、
#a=123
#[ ! $a = ~^[0-9] ] && echo "$a right" || echo "$a error"
expr $a+0 &>/dev/null
RETVAL=$?
test $RETVAL -eq 0 {echo "number"
exit 1
}
方法二、将数字全部用空格代替
[ -n "`echo $1|sed 's/[0-9]//g'`" ]&& { echo ...}
方法三、
#a=123
#[ ! $a = ~^[0-9] ] && echo "$a right" || echo "$a error"
温馨提示:答案为网友推荐,仅供参考