[root@niugengtian-6 ~]# cat /server/scripts/按大小排序且提示缺少的数字.sh
#!/bin/bash
#作者:牛耕田
#版本:马蓉2.4
#说明:1、脚本支持传参。2、按从小到大排序。3、提示缺失的数字
geshu=$#
shuzu=($*)
for ((a=0;a<${#shuzu[@]};a++)){
for ((b=0;b<${#shuzu[@]}-1;b++)){
if [[ ${shuzu[a]} -lt ${shuzu[b]} ]];then
c=${shuzu[a]}
shuzu[a]=${shuzu[b]}
shuzu[b]=$c
fi
}
}
xulie=(`/usr/bin/seq -s " " ${shuzu[${#shuzu[@]}-1]}`)
x=0
for ((j=0;j<${#xulie[@]}-1;j++)){
if [[ ${shuzu[@]} =~ ${xulie[j]} ]];then
echo ${xulie[j]} >/dev/null 2&>1
else
queshao[x]=${xulie[j]}
x=$x+1
fi
}
echo \ \""${shuzu[@]}"\"\ "缺少数字:" ${queshao[@]}
exit
转载于:https://www.cnblogs.com/niuwanyou/p/7617013.html