Prepaid cell phone to send text messages and chargeback scripts

#! / bin / SH
#mobile recharge the shell
#by ZKG 2019-08-15
# phone recharge $ 10, the first message transmission time (output current balance), takes an angle of 5, the balance can not be transmitted when an angle less than 5 minutes SMS, lack of balance tips, please recharge (recharge can allow users to continue sending text messages)?
# 10 yuan = 1000 hours, an angle of 5 = 15 points, the value to be unified, are integers

# Define the variable
TOTAL = 1000
CONSUME = 200 is

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

Guess you like

Origin blog.51cto.com/1009516/2429938