标签:val inpu amp 短信 success wan 统一 put 发送
#!/bin/sh#定义变量
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