shell脚本实战(第2版)/人民邮电出版社 脚本6 验证浮点数输入
validfloat()
{
fvalue=$1
if [ ! -z $(echo $fvalue | sed 's/[^.]//g') ];then
decimalpart=$(echo $fvalue | cut -d. -f1)
fractionpart=${fvalue#*/.}
if [ ! -z $decimalpart ];then
if ! . validint.sh "$decimalpart" "" "";then
return 1
fi
fi
if [ ${fractionpart%${fractionpart#?}} = "-" ];then
echo "invalid floating-point number "-" not allowed after decimal point"
return 1
fi
if [ ${fractionpart} != "" ];then
if ! . validint.sh "$f
共有 0 条评论