结合阵列中一个for循环(击)的开始 [英] Combine arrays in the beginning of a for-loop (Bash)
本文介绍了结合阵列中一个for循环(击)的开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能做这样的事情?
A =(1 2 3)
B =(4 5 6)
在($ {A [@]} $ {B [@]})#NUM或:在$ {NUM($ {A [@]} $ {B [@]})[@]}
做
回声$ NUM
DONE
#输出1 2 3 4 5 6
我知道你可以再前循环将它们结合起来,通过他们,但有可能在只有一条线?
目前的解决方案:
A =(1 2 3)
B =(4 5 6)
C =($ {A [@]} $ {B [@]})
在$ {NUM C [@]}
做
回声$ NUM
DONE
#输出1 2 3 4 5 6
解决方案
同时指定数组。
于民$ {A [@]}$ {B [@]}
...
Is it possible to do something like this?
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
I know you can combine them before and then loop through them, but is it possible in only one line?
Current solution:
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
解决方案
Specify both arrays.
for num in "${a[@]}" "${b[@]}"
...
这篇关于结合阵列中一个for循环(击)的开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文