Shell编程之if简单判断两个数字大小

#脚本编辑


 

#!/bin/bash

#定义变量
num1=$1
num2=$2
 
#判断是否输入两个参数,若是,将两个参数传递给下一个指令动作,若非两个参数,则打印输出内容输出并且退出exit脚本不执行下一个指令
if [ $# -ne 2 ] ;then
   echo 'please input num1 & num2:'
exit
fi
 
#以上判断后,输入的两个参数将传递到如下指令判断
if [ $num1 -gt $num2 ] ; then
   echo $num1 great than $num2
 
else if [ $num1 -lt $num2 ] ; then
   echo $num1 less than $num2
 
else
   echo $num1 equal $num2
 
fi  
fi
 

 
#验证是否正确
 
[root@lin scripts]# sh compare2.sh 66
please input num1 & num2:
[root@lin scripts]# sh compare2.sh 10 10
10 equal 10
[root@lin scripts]# sh compare2.sh 10 1
10 great than 1
[root@lin scripts]# sh compare2.sh 10 50
10 less than 50
[root@lin scripts]# sh compare2.sh 6 7 8 9 10
please input num1 & num2:
 
 
 

转载于:https://www.cnblogs.com/linyushuan/p/9937796.html

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值