#!/bin/sh
var=`echo $1 | bc 2>/dev/null`
if [ "$var" != "$1" ]; then
echo "$1 is not a number"
else
echo "$1 is a number"
fi
# ./tmp.sh dfa
dfa is not a number
# ./tmp.sh 333
333 is a number
# ./tmp.sh -330
-330 is a number
# ./tmp.sh 3.1139
3.1139 is a number
# ./tmp.sh 33aa
33aa is not a number
#!/bin/sh
var=`echo $1 | bc 2>/dev/null`
if [ "$var" != "$1" ]; then
echo "$1 is not a number"
else
echo "$1 is a number"
if echo $var | grep "\." > /dev/null; then
echo $var is a float
else
echo $var is not a float
fi
fi
# ./tmp.sh 3333
3333 is a number
3333 is not a float
# ./tmp.sh 3333.222
3333.222 is a number
3333.222 is a float
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |