#!/bin/sh
#手机充值10元,没发一条短信(输出当前余额)花费1角5分,宕余额低于0.15时不能发短信,提士”余额不足,请充值“(允许充值后继续发短信),whil
red_color='\E[1;31m'
blue_color='\E[1;34m'
yellow_color='\E[1;33m'
res='\E[0m'
total=10
chose(){
echo -e "==============
$red_color
1.send message
2.add money
3.query money
$res
============="
read -p "which chose?" chose
case $chose in
1)
send;;
2)
add;;
3)
query;;
*)
echo -e "$blue_color input 1 or 2 or 3 $res"
chose;;
esac
}
send(){
permess=0.15
if [ $total -gt $permess ];then
echo "send a message"
total=`echo "$total - $permess"|bc` #<==bc支持小数点的运算
echo -e "$blue_color remain money :$total $res"
else
echo -e "$yellow_color not sufficient funds! can't send message please add money $res"
fi
}
query(){
echo -e "$blue_color now total money is $total $res"
}
add(){
echo "now total is $total"
read -p "add money:" add
expr $add + 1 >/dev/null 2>&1
if [ $? -ne 0 ];then
echo "please input a num"
add
else
# total=$(($total+$add))
# total=`echo "$total + $add"|bc`
total=$(echo "$total + $add"|bc)
echo -e "$blue_color add $add money;total is:$total $res"
fi
}
main(){
while true
do
chose
done
}
main
#手机充值10元,没发一条短信(输出当前余额)花费1角5分,宕余额低于0.15时不能发短信,提士”余额不足,请充值“(允许充值后继续发短信),whil
red_color='\E[1;31m'
blue_color='\E[1;34m'
yellow_color='\E[1;33m'
res='\E[0m'
total=10
chose(){
echo -e "==============
$red_color
1.send message
2.add money
3.query money
$res
============="
read -p "which chose?" chose
case $chose in
1)
send;;
2)
add;;
3)
query;;
*)
echo -e "$blue_color input 1 or 2 or 3 $res"
chose;;
esac
}
send(){
permess=0.15
if [ $total -gt $permess ];then
echo "send a message"
total=`echo "$total - $permess"|bc` #<==bc支持小数点的运算
echo -e "$blue_color remain money :$total $res"
else
echo -e "$yellow_color not sufficient funds! can't send message please add money $res"
fi
}
query(){
echo -e "$blue_color now total money is $total $res"
}
add(){
echo "now total is $total"
read -p "add money:" add
expr $add + 1 >/dev/null 2>&1
if [ $? -ne 0 ];then
echo "please input a num"
add
else
# total=$(($total+$add))
# total=`echo "$total + $add"|bc`
total=$(echo "$total + $add"|bc)
echo -e "$blue_color add $add money;total is:$total $res"
fi
}
main(){
while true
do
chose
done
}
main