注意:若直接復(fù)制的的話腳本內(nèi)容格式會(huì)非常亂解決方法
1.Esc
2.光標(biāo)到開(kāi)頭Ctrl+v
3.上下鍵選中所有
4.按=即可恢復(fù)正確格式
注:腳本內(nèi)容cat追加部分:cat與最后一個(gè)EOF需頂格,自行手動(dòng)修改
#!/bin/bash
sum=30 #初始余額總數(shù)
msg=15 #發(fā)一條短信需要15分
menu () {
cat << EOF
當(dāng)前余額為$sum 分,每條短信需要$msg 分
==========================
1.充值
2.發(fā)消息
3.退出
==========================
EOF
}
recharge () {
read -p "請(qǐng)輸入充值金額:" money
sleep 1
clear
expr $money + 1 &>/dev/null
if [ -z $money ];then
echo "不能為空,請(qǐng)重新輸入"
ec
recharge
fi
expr $money + 1 &>/dev/null
if [ $? -eq 0 ];then
((sum=$sum+$money))
echo "充值成功驾讲,剩余余額為:$sum"
main
else
ec
echo "請(qǐng)輸入要充值的正確的金額(正整數(shù))械蹋!"
recharge
fi
}
ec () {
echo " "
}
note () {
read -p "輸入要發(fā)送的內(nèi)容:" note
((sum=$sum-$msg))
echo "發(fā)送成功焚廊,余額剩余:$sum"
}
yno () {
read -p "請(qǐng)問(wèn)是否繼續(xù)發(fā)送(yes/no):" yno
ec
if [ "$yno" == "yes" ];then
news
note
elif [ "$yno" == "no" ];then
sleep 1
clear
main
else
echo "請(qǐng)輸入(yes或者no)"
yno
fi
}
panduan () {
read -p "是否充值(yes/no):" yn
ec
if [ "$yn" == "yes" ];then
recharge
elif [ "$yn" == "no" ];then
# menu
main
else
echo "請(qǐng)輸入(yes或者no)"
panduan
fi
}
news () {
if [ $sum -lt 15 ];then
echo "余額不足$msg厂置,請(qǐng)充值"
panduan
else
while true
do
if [ $sum -lt 15 ];then
echo "余額不足$msg橱乱,如想發(fā)送短信請(qǐng)充值"
panduan
else
ec
read -p "輸入要發(fā)送的內(nèi)容:" note
((sum=$sum-$msg))
echo "發(fā)送成功弟塞,余額剩余:$sum"
ec
yno
if [ $sum -lt $msg ];then
ec
echo "余額不足稿械,剩余$sum分"
panduan
menu
fi
fi
done
fi
}
main () {
while true
do
menu
ec
read -p "請(qǐng)選擇要做的操作:" a
sleep 1
clear
case $a in
1)
recharge
;;
2)
news
;;
3)
exit 0
;;
*)
echo "輸入錯(cuò)誤,請(qǐng)輸入正確的選項(xiàng)"
esac
done
}
main
能夠發(fā)郵件的
#!/bin/bash
sum=30 #初始余額總數(shù)
msg=15 #發(fā)一條短信需要15分
mails=`cat /etc/mail.rc |wc -l`
menu () {
cat << EOF
當(dāng)前余額為$sum 分,每條短信需要$msg 分
==========================
1.充值
2.發(fā)消息
3.退出
==========================
EOF
}
recharge () {
read -p "請(qǐng)輸入充值金額:" money
sleep 1
clear
expr $money + 1 &>/dev/null
if [ -z $money ];then
echo "不能為空,請(qǐng)重新輸入"
ec
recharge
fi
expr $money + 1 &>/dev/null
if [ $? -eq 0 ];then
((sum=$sum+$money))
echo "充值成功乏沸,剩余余額為:$sum"
main
else
ec
echo "請(qǐng)輸入要充值的正確的金額(正整數(shù))淫茵!"
recharge
fi
}
ec () {
echo " "
}
mail () {
if [ $mails -lt 70 ];then #注意,/etc/mail.rc默認(rèn)為69行蹬跃,若曾經(jīng)修改過(guò)需要手動(dòng)修改
cat >>/etc/mail.rc<< EOF
set from=xxxxxxx@163.com smtp=smtp.163.com smtp-auth-user=xxxxxxx smtp-auth-password=xxxxxxxxxxxxxx smtp-auth=login
EOF
else
:
fi
}
note () {
read -p "輸入要發(fā)送的內(nèi)容:" note
((sum=$sum-$msg))
echo $note >/tmp/youjian.txt
mailx -s "短信" xxxxxxxxx@126.com </tmp/youjian.txt
echo "發(fā)送成功匙瘪,余額剩余:$sum"
}
yno () {
read -p "請(qǐng)問(wèn)是否繼續(xù)發(fā)送(yes/no):" yno
ec
if [ "$yno" == "yes" ];then
news
note
elif [ "$yno" == "no" ];then
sleep 1
clear
main
else
echo "請(qǐng)輸入(yes或者no)"
yno
fi
}
panduan () {
read -p "是否充值(yes/no):" yn
ec
if [ "$yn" == "yes" ];then
recharge
elif [ "$yn" == "no" ];then
main
else
echo "請(qǐng)輸入(yes或者no)"
panduan
fi
}
news () {
if [ $sum -lt 15 ];then
echo "余額不足$msg,請(qǐng)充值"
panduan
else
while true
do
if [ $sum -lt 15 ];then
echo "余額不足$msg蝶缀,如想發(fā)送短信請(qǐng)充值"
panduan
else
ec
note
ec
yno
if [ $sum -lt $msg ];then
ec
echo "余額不足丹喻,剩余$sum分"
panduan
menu
fi
fi
done
fi
}
main () {
while true
do
menu
ec
read -p "請(qǐng)選擇要做的操作:" a
sleep 1
clear
case $a in
1)
recharge
;;
2)
news
;;
3)
exit 0
;;
*)
echo "輸入錯(cuò)誤,請(qǐng)輸入正確的選項(xiàng)"
esac
done
}
main