[root@host ]# cat test.sh
#!/bin/bash
test=$1
echo "$test"|[ -n "`sed -n '/^[0-9][0-9]*$/p'`" ] #纯数字返回值为0,不是纯数字返回值不等于0
if [ "$?" = "0" ];then #判断返回值是否为0
echo "$test is number" #返回值等于0则执行
else
echo "$test not number" #反之返回值不等于0则执行
fi
[root@host ]# sh test.sh 1234
1234 is number
[root@host ]# sh test.sh 12345
12345 is number
[root@host ]# sh test.sh 12345d
12345d not number
[root@host ]# sh test.sh 12345a
12345a not number
[root@host ]# sh test.sh 12345a123
12345a123 not number