新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

使用SHELL完成两个数字的大小比较-创新互联

简要说明:

站在用户的角度思考问题,与客户深入沟通,找到黄平网站设计与黄平网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广、域名注册虚拟主机、企业邮箱。业务覆盖黄平地区。

提示用户输入两个数字;

判断输入的内容是否都为数字;

数字做计算并反馈结果;

计算完毕后询问客户是否继续使用;

给用户提供随时退出的方法。

[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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文名称:使用SHELL完成两个数字的大小比较-创新互联
转载注明:http://www.wjwzjz.com/article/dpjogs.html
在线咨询
服务热线
服务热线:028-86922220
TOP