如何在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
在每种情况下,它都会将one
和two
视为命令:(
答案 0 :(得分:5)
您尝试过:
for i in "one" "two"; do echo "$i"; done