1,用输入的字符串和任意一个数字进行运算,可以判断!
代码:
#!/bin/ksh
#
var=$(echo "$1*1"|bc)
if [[ $var != 0 ]]
then
echo "$1 is a number"
else
echo "$1 is a charter"
fi
2,用流编辑器sed!
代码:
if [ -n "`echo $1|sed -n '/^[0-9][0-9]*$/p'`" ]
then
echo "$1 is number!"
else
echo "$1 is not number!"
fi
3,用awk来判断!
代码:
echo $1|awk '{if($0~/[^0-9]/) {print "'$1' is not number"} else{print "'$1' is number"}}'