Bash脚本在循环中设置变量

时间:2018-07-28 06:05:03

标签: linux bash

我想为变量中的所有字符串(一个一个地)运行一个for循环。当我回显我的变量时,就像这样

A=(curl -s 'localhost:9200/something)
echo "$A"

发射:

sss
ddd
fff
ggg
hhh

我的for循环是这样的:

for i in "${A[@]}"; do
  echo "$i"
  echo test
 done

但是循环仅运行一次并打印所有数据,而不是在每个项目之后放置test

sss
ddd
fff
ggg
hhh
test

1 个答案:

答案 0 :(得分:0)

@PresaThe建议,

while read line ; do  echo "$line" ; echo testsss; done <  <(curl -s 'localhost:9200/something)