可以这样做吗?
a=( 1 2 3 ) b=( 4 5 6 ) for num in ( ${a[@]} ${b[@]} ) # or: for num in ${( ${a[@]} ${b[@]} )[@]} do echo "$num" done # Outputs 1 2 3 4 5 6
我知道你可以先将它们组合起来然后循环它们,但它是否只能在一行中完成?
当前解决方案
a=( 1 2 3 ) b=( 4 5 6 ) c=( ${a[@]} ${b[@]} ) for num in ${c[@]} do echo "$num" done # Outputs 1 2 3 4 5 6
指定两个数组.
for num in "${a[@]}" "${b[@]}" ...