for loop with multiline data

I need to create a script with a loop through a list of items. I want to insert a string in the script.

I tried:

for i in "
a
b
c";
do
 echo "test "$i
done

But that only outputs one string:

test a b c

How would I get this?

testa
testb
testc

(a, b and c are just examples for some longer words, which I got from an OpenOffice Calc file)

Asked By: rubo77

||

You’d use a while loop instead.

while read i
do
  echo "test$i"
done <<< 'a
b
c'
export a="
a
b
c
"

for i in $a; do echo "test$i";done
Answered By: Bonsi Scott
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.