shell脚本-随机输入几个整数 ,脚本返回最大值

脚本目标:

脚本后 随机输入几个整数,实现返回其中最大值

脚本内容:

#!/bin/bash

typeset MAX=$1

if [ $# -le 1 ];then
        echo "You need to enter more than two numbers, please enter again."
        exit
else

  for i in $@
    do
      if [ $MAX -le $i ];then
            MAX=$i
      fi

    done

  echo "the max number is:$MAX"
fi

 

运行结果:

[root@node1 script]# 
[root@node1 script]# sh max_num.sh 45 78 5454 12154 5787 
the max number is:12154
[root@node1 script]# 

 

posted @ 2021-12-31 16:23  布莱ent  阅读(263)  评论(0)    收藏  举报