首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

shell中判断变量是不是是数字

2012-09-14 
shell中判断变量是否是数字1、http://www.kuqin.com/article/24shell/172512.htmlvar$(echo $1|bc 2/dev/

shell中判断变量是否是数字
1、http://www.kuqin.com/article/24shell/172512.html

var=$(echo $1|bc 2>/dev/null)
if [[ $var != $1 ]]
        then
        echo "$1 isn't a number!"
        exit 1
fi
if echo $1|grep "\." >/dev/null 2>&1
        then
        echo "$1 is float a number!"
        else
        echo "$1 is integer a number!"
fi

热点排行