如何在bash for循环中内联一个字符串数组?

时间:2015-12-11 21:54:17

标签: bash

如何在bash for循环中内联一个字符串数组?这有效:

array=(one two)
for i in ${array[*]};do echo $i; done

但我想消除额外的局部变量。我尝试了许多似乎合理的变体,例如:

for i in ${("one" "two")[*]};do echo $i; done

for i in ${"one" "two"};do echo $i; done

在每种情况下,它都会将onetwo视为命令:(

1 个答案:

答案 0 :(得分:5)

您尝试过:

for i in "one" "two"; do echo "$i"; done