2.生成10个随机数保存于数组中,并找出其最大值和最小值
[root@CentOS8 ~]# cat array_max_min.sh
!/bin/bash
********************************************************************
Author: Hbiaoming
QQ: 123456789
Date: 2022-07-14
FileName: array_max_min.sh
URL: www.haha.cn
Description: The test script
Copyright (C): 2022 All rights reserved
********************************************************************
declare -i min max
declare -a nums
for ((i=0;i<10;i++));do
nums[$i]=$RANDOM
[ $i -eq 0 ] && min=${nums[$i]} && max=${nums[$i]} && continue
[ ${nums[$i]} -gt $max ] && max=${nums[$i]}
[ ${nums[$i]} -lt $min ] && min=${nums[$i]}
done
echo “All numbers are ${nums[*]}”
echo Max is $max
echo Min is $min
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/274829.html