SHELL练习--手机充值
2016-08-03 14:48
288 查看
[root@db02 shell]# cat phone_recharge01.sh #!/bin/bash balance=15 message_cost=15 RED_COLOR='\E[1;31m' GREEN_COLOR='\E[1;32m' YELLOW_COLOR='\E[1;33m' BLUE_COLOR='\E[1;34m' PINK='\E[1;35m' RES='\E[0m' color(){ if [ "$2" = "red" ];then echo -e "${RED_COLOR}$1 $RES" elif [ "$2" = "green" ];then echo -e "${GREEN_COLOR}$1 $RES" elif [ "$2" = "yellow" ];then echo -e "${YELLOW_COLOR}$1 $RES" else echo "color error."&& exit 1 fi } Send_Message(){ echo -e "you have balance \E[1;32m$balance\E[0m,message \E[1;32m$(($balance/${message_cost}))\E[0m left..." read -p "Input you message:" message read -p "To whom you want to send:" user echo -e "\E[1;32mSend:\E[0m $message\n\E[1;32mTo:\E[0m $user" read -p "Sure?[y|n]:" option case "$option" in Y|y) color "Send successful." green ;; N|n) exit 2 ;; *) color "Input error..." red Send_Message ;; esac } Recharge(){ read -p "Insufficient balance $balance,recharge right now?[Y|N]:" option case "$option" in Y|y) while true do read -p "Input money:" money expr $money + 1 &>/dev/null [ $? -eq 0 -a $money -gt 0 ] 2>/dev/null &&break||{ color "Invalid Input,money must be int..." red } done ((balance=balance+money)) color "Recharge successful,you balance is $balance .." green [ $balance -le 15 ]&& Recharge ;; N|n) color "bye..." yellow exit 3 ;; *) color "Input error..." red Recharge ;; esac } main(){ while [ $balance -ge 15 ] do Send_Message ((balance=balance-${message_cost})) [ $balance -le 15 ]&& Recharge done } main
相关文章推荐
- shell脚本练习
- shell练习
- 如何使用shell脚本对android手机的操作---初级篇1
- shell adb遍历android手机sdcard下的所有文件,包含隐藏文件,略过链接
- 【shell脚本练习】批量添加用户和设置密码
- shell脚本练习(12.10)
- shell 脚本练习。笔记
- shell练习
- 5个Shell脚本编程入门练习例子
- 通过adb shell命令切换手机的输入法
- 每日一道shell练习(06)——检测端口服务
- 学习shell——编程练习
- ubuntu下调试android手机,并进入手机shell终端
- 郭克华手机编程教学视频----我的练习源码(7)List的介绍
- 郭克华手机编程教学视频----我的练习源码(15)案例:手机短信
- 郭克华手机编程教学视频----我的练习源码(16)定时器,背景光,震动测试
- Linux-shell练习20171222
- shell 练习
- 仿淘宝话费充值手机号码提示