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
结果:
**************
abcdefxxxxxxxxxxxxxxghijklxxxxxxxxxxxxxxmnop