|
发表于 2003-11-27 18:16:24
|
显示全部楼层
呵呵,俺也写了一个学习学习,,,
脚本:
$cat ./count.sh
#!/bin/sh
profit=
while [ -z "$profit" ];
do
printf "%s" " lease input a number:"
read profit
nums=`expr $profit + 0 > /dev/null 2>&1`
###似乎没什么好方法检验输入数字是否合法,所以就用了这个笨方法
if [ $? -ne 0 ];then
echo "Input invalid,please input again!!"
profit=
fi ##判断输入是否合法
done
if [ $profit -le 100000 ]; then
bonus=`expr $profit \* 10 / 100`
elif [ $profit -le 200000 ]; then
bonus=`expr $profit \* 75 / 1000 + 2500`
elif [ $profit -le 400000 ]; then
bonus=`expr $profit \* 5 / 100 + 7500`
elif [ $profit -le 600000 ]; then
bonus=`expr $profit \* 3 / 100 + 19500`
elif [ $profit -le 800000 ]; then
bonus=`expr $profit \* 15 / 1000 + 24500`
else
bonus=`expr $profit / 100 + 29500`
fi
echo " rofit is $profit"
echo "Bonus is $bonus"
大同小异,反正这个也比较简单,
对于shell来说,数学运算得到的小数点以后的部分都被舍去了!!
输出:
$ ./count.sh
Please input a number:120050
Profit is 120050
Bonus is 11503
$ ./count.sh
Please input a number:ssss2
Input invalid,please input again!!
Please input a number:
$ ./count.sh
Please input a number:3312 23
Input invalid,please input again!!
Please input a number: |
|