标签:cat class color fse tin ber 数组 declare set
1 #!/bin/env sh
2
3 declare -i max=0
4 declare -i min=32765
5 declare -a zz
6
7 for x in `seq 0 1 9`;do
8 zz[x]=$RANDOM
9 [ ${zz[x]} -gt $max ] && max=${zz[x]}
10 [ ${zz[x]} -lt $min ] && min=${zz[x]}
11 done
12
13 echo ${zz[@]}
14 echo $max,$min
1 #!/bin/env sh
2
3 declare -a bb
4 declare -i sum=0
5
6 bb=(/var/log/*.log)
7
8 for x in `seq 0 2 $[${#bb[*]}-1]`;do
9 let sum+=`cat ${bb[x]}|wc --lines`
10 done
11
12 echo $sum
1 #!/bin/env sh
2
3 declare -a pp
4 declare -i sum
5
6 pp=(/var/log/*.log)
7
8 for b in `seq 0 1 $[${#pp[*]}-1]`;do
9 if [ $[b%2] -ne 0 ];then
10 continue
11 fi
12
13 let sum+=`wc --lines ${pp[b]}|awk ‘{print $1}‘`
14 done
15
16 echo ${pp[*]},$sum
${bb[*]:5:3}
数组切片${array[@]:offset:number}
数组亦支持反向索引
echo ${array[-1]}
echo ${array[-2]}
追加元素
array[${#array[*]}]="variable"
删除数组元素
unset array[index]
关联数组
declare -A array_name
标签:cat class color fse tin ber 数组 declare set
原文地址:https://www.cnblogs.com/dissipate/p/12979948.html