【发布时间】:2017-07-03 01:08:55
【问题描述】:
对于使用两个或多个数组的嵌套循环,例如
A=(0.1 0.2)
B=(2 4 6)
AB=$((${#A[@]}*${#B[@]})) # total number of iterations (length of A * length of B)
for a in ${A[*]}; do
for b in ${B[*]}; do
$(($a+$b)) # task using each combination of A and B
echo ? # show number of the iteration (i.e. 1 to length of AB)
done
done
如上所示使用echo,获取迭代次数的最佳方法是什么?
【问题讨论】:
标签: arrays bash loops unix for-loop