printing variable with variable suffix through loop

I have a group of variables myLINEcnt1 - myLINEcnt10. I'm trying to printout the values using a for loop. I am at the head banging stage since i'm sure it has to be a basic syntax issue that i can't figure out.

For myIPgrp in 1 2 3 4 5 6 7 8 9 10; do
here i want to output the value of myLINEcnt[1-10]

but every attempt i've tried either errors or give me just the number portion (1-10)

echo ${myLINEcnt}${myIPgrp}

Crap, i'm an idiot. SORRY I'm using bash on a Centos 5.7 system.

Thanks in advance.

You need to use eval to access dynamically generated variable names. And, as a further hint, with eval you'll need to quote the first $ . Since eval can execute arbitrary code, use it with caution. This particular use should be fine. Read your shell man page for the details.

Your shell may provide a better alternative. Perhaps arrays. Or references. If you want help with the bigger picture, tell us which shell and os you're using and what you're trying to accomplish.

Regards,
Alister

Crap, i'm an idiot. SORRY I'm using bash on a Centos 5.7 system.

for i in myIPgrp{1..10}; do
         echo ${!i}
done
1 Like

Well crud, i figured it was an easy answer but DUH!. Never done it that way but i will be, thanks.

what is the ! doing???

Oh i actually use

for i in myLINEcnt{1..10} do

I will still be looking at the eval method, getting that to work will help me in the future.