码迷,mamicode.com
首页 > 移动开发 > 详细

手机发送短信扣费和充值脚本

时间:2019-08-15 23:06:48      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:val   inpu   amp   短信   success   wan   统一   put   发送   

#!/bin/sh
#mobile recharge shell
#by zkg 2019-08-15
#手机充值10元,第发送一次短信(输出当前余额),花费1角5分,当余额低于1角5分不能发送短信,提示余额不足,请充值(可以允许用户充值继续发送短信)?
#10元=1000分,1角5分=15分,数值要统一,都为整数

#定义变量
TOTAL=1000
CONSUME=200

function isnum(){
expr $1 + 1 &>/dev/null
if [ $? -ne 0 -a "$1" != "-1" ];then
return 1
fi
return 0
}

function consume(){
read -p "please input your message:" content
read -p "Are you sure send?{y|Y|n|N}:" option
case $option in
y|Y)
echo "send $content successfully!!!"
((TOTAL=TOTAL-CONSUME))
echo "you money haved $TOTAL availed"
;;
n|N)
echo "canceled"
;;
*)
echo "invalid input"
;;
esac
}

function recharge(){
if [ $TOTAL -le $CONSUME ];then
echo "you money haved $TOTAL availed,it is not enough!!!"
read -p "you want to recharge money?{y|Y|n|N}:" option2
case $option2 in
y|Y)
while true
do
read -p "please input recharge money?[INT]:" CHARGE
isnum $CHARGE && break ||{
echo "invalid input"
exit 100
}
done
((TOTAL=TOTAL+CHARGE)) && echo "you have $TOTAL money"
;;
n|N)
echo "canceled"
exit 101
;;
*)
echo "invalid input"
exit 102
;;
esac
fi
}

function main(){
while [ $TOTAL -ge $CONSUME ]
do
consume
recharge
done
}
main

手机发送短信扣费和充值脚本

标签:val   inpu   amp   短信   success   wan   统一   put   发送   

原文地址:https://blog.51cto.com/1009516/2429939

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!