I have a bash loop, I\'m trying to read the all variables:
var1=\"hello1\"
var2=\"hello2\"
var3=\"hello3\"
for i in `seq 1 3`;
do
ab=var$i
# Now ab == var1,
Simpler approach:
var1="hello1"
var2="hello2"
var3="hello3"
eval echo\ $var{1..3}\;
Is expanded to:
echo $var1
echo $var2
echo $var3
Ouput:
hello1
hello2
hello3
var1="hello1"
var2="hello2"
var3="hello3"
for i in `seq 1 3`;
do
ab=var$i
echo ${!ab}
done
I'm not sure it is the best solution to your larger problem, but it is the direct solution to your immediate request.