[root@centos8-0 ~]# vim array_random.sh#!/bin/bash#declare -i min max
declare -a num
for((i=0;i<10;i++));do
num[$i]=$RANDOMif[$i -eq 0];thenmax=${num[$i]}min=${num[$i]}elif[${num[$i]} -gt $max];thenmax=${num[$i]}elif[${num[$i]} -lt $min];thenmin=${num[$i]}fidoneecho"all numbers are ${num[*]}"echo"max=$max"echo"min=$min"[root@centos8-0 ~]# bash array_random.sh
all numbers are 31423187142071025778434870122396418898506614794max=31423min=4348
3、输入若干个数值存入数组中,采用冒泡算法进行升序或降序排序
[root@centos8-0 ~]# vim bubble_sort.sh#!/bin/bash#echo -n "请输入数字列表,\"格式:n1 n2 ...\": "read -a num
for((i=0;i<${#num[*]};i++));dofor((j=0;j<${#num[*]}-1;j++));doif[[${num[$j]} -lt ${num[$j+1]}]];thentmp=${num[$j]}
num[$j]=${num[$j+1]}
num[$j+1]=$tmpfidonedoneecho${num[*]}[root@centos8-0 ~]# bash bubble_sort.sh
请输入数字列表,"格式:n1 n2 ...":110119120112120119112110
[root@centos8-0 ~]# cd /data[root@centos8-0 data]# vim for_scan_host.sh#!/bin/bash# NET=192.168.0
forIDin{1..254};do{ping -c1 -W1 ${NET}.${ID}&>/dev/null &&echo"${NET}.$ID is sussess."||echo"${NET}.${ID} is fail.";}&donewait
-------------------------------------------------------------------------------------------------------
[root@centos8-0 data]# vim while_scan_host.sh#!/bin/bash#NET=192.168.0
ID=1whiletruedoif[$ID -le 254];then{ping -c1 -W1 ${NET}.${ID}&>/dev/null &&echo"${NET}.${ID} is success."||echo"${NET}.${ID} is fail."}&elseexitfilet ID++
donewait