files=(a b c d e f g h i j k l m n o p)
cnt="${#files[@]}"
let cnt1="($cnt+2)/3"
let cnt2="$cnt1*2"
let cnt3="$cnt-$cnt2"
files_part1=( "${files[@]:0:$cnt1}" )
files_part2=( "${files[@]:$cnt1:$cnt1}" )
files_part3=( "${files[@]:$cnt2:$cnt3}" )
printf '%s\n' "${files_part1[@]}"
echo "xxxxxxxxxxxxxx"
printf '%s\n' "${files_part2[@]}"
echo "xxxxxxxxxxxxxx"
printf '%s\n' "${files_part3[@]}"
#for each in "${files[@]}"; do
#echo "$each"
#done
结果:
**************
a
b
c
d
e
f
xxxxxxxxxxxxxx
g
h
i
j
k
l
xxxxxxxxxxxxxx
m
n
o
p
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6697633.html,如需转载请自行联系原作者