Hi There,
var1=value1
var2=value2
var3=value3
for (( i=1; i<4; i++ ))
do
temp=var$i
echo "$temp"
done
OUTPUT
var1
var2
var3
I want the output to be
value1
value2
value3
How can I achieve this?
Regrads
Jagpreet
Hi There,
var1=value1
var2=value2
var3=value3
for (( i=1; i<4; i++ ))
do
temp=var$i
echo "$temp"
done
OUTPUT
var1
var2
var3
I want the output to be
value1
value2
value3
How can I achieve this?
Regrads
Jagpreet
There's a specific construct called an array which associates values with an index, assuming this is a bash script, take a look at the chapter on arrays in the bash beginners guide otherwise do a search for arrays in the documentation of this shell
Thanks for the reply.
eval did the trick.
Thanks anyway
Please use code tags as required by forum rules!
With a recent bash, you can try
for i in var{1..4}; do temp=${!i}; echo "$temp"; done
value1
value2
value3
You can, the question is should you when there's a perfectly good array construct available?
Depends on the problem being solved, which we know nothing about. Arrays are used to solve far too many "problems" in shell, sometimes used to excess.