0

This question already has an answer here:

I want echo a variable's value in a bash script using a for loop.

Example:

var1=test1;
var2=test2; 
for i in seq 1 2
do 
    echo "$var$i";
done

My output:

1
2

But I want to echo this:

test1
test2

marked as duplicate by Eric Renouf, Kusalananda, ilkkachu, Jeff Schaller, tripleee Apr 28 '17 at 15:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

That's not how identifiers work. If you want to loop through a set of variables like that, use array instead. Here's what is happening: Only $i is printed as 1 and 2, $var has no value so it is not printed.

In "$var$i" , $var and $i are treated as separate variables.

Not the answer you're looking for? Browse other questions tagged or ask your own question.