新聞中心
簡要說明:
提示用戶輸入兩個數(shù)字;
判斷輸入的內(nèi)容是否都為數(shù)字;
數(shù)字做計算并反饋結(jié)果;
計算完畢后詢問客戶是否繼續(xù)使用;
給用戶提供隨時退出的方法。
[root@lb02 scripts]# cat jisuan2.sh
#!/bin/bash
###thank_oldboy
###2016/3/6
###i wish you all the best.
. /etc/init.d/functions
### read number.
function read_number(){
read -p "please enter the number1:" num1
read -p "please enter the number2:" num2
panduan_number
}
### judge $number1 $number2 both are number.
function panduan_number() {
expr $num1 + $num2 &>/dev/null
[ $? -ne 0 ] && {
[[ $num1 == exit || $num2 == exit ]] && {
echo "you had choice leave,bye."
exit 0
} || {
echo "USAGE:you must enter two numbers, or enter exit to leave."
read_number
}
} || judge_number
}
### judge continue or exit.
function continue_or_exit() {
read -p "please enter go to continue or enter out to leave: " str
case "$str" in
go)
read_number
;;
out)
echo "hope to see you again,bye."
exit 0
;;
*)
echo "USAGE:enter go or out:"
continue_or_exit
;;
esac
}
### expr $number1 $number2.
function judge_number() {
[ $num1 -eq $num2 ] && {
echo "$num1 equal $num2."
continue_or_exit
}
[ $num1 -gt $num2 ] && {
echo "$num1 greater than $num2."
continue_or_exit
}
[ $num1 -lt $num2 ] && {
echo "$num1 lower than $num2."
continue_or_exit
}
}
### the gate of the script.
function main() {
read_number
}
main
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
新聞名稱:使用SHELL完成兩個數(shù)字的大小比較-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://fisionsoft.com.cn/article/dpjogs.html