Creating bash array name from variable

Hi gurus,

I need to create arrays from variables, via a loop.

The issue I have is with the array name creation. How do I use a variable to define an array?

I want to do something like
declare -a $H
where $H is my loop variable.

I then need to add items to each array I've created, something like this
$H=( ${$H[@]} "$I")

$I is the variable I'm using to loop in the array items.

I'm guessing that I'll need to use eval but nothing I've tried works. Escaping non-printable characters doesn't work either.

I can define an empty array using the $H variable, but I'm unable to add items to it or print out the full array item list.
I have no problems when defining a non-variable array name, but I need to create over 100 lookup tables, with number of items ranging from 1 to 10 -15 for each array, all from loop.

Any suggestions would be most welcolmed

H[${#H[*]}]=$I

Guru.

Thanks Guru, but not sure if this is what I'm after.

example of my code is:

e.g. Array name (H) could contain a persons name. The items (I) in the array could include things like address, phone number, D.O.B.

So I need to use a for loop to create the initial arrays (persons name), then use another for loop to populate the arrays with specific items. Then I need to be able to print out specific items or the entire array.
The issue looks to be with my variable expansion, but I could be wrong.

Does this make better sense?

Perhaps this might help:

H=boats
eval $H'[1]="Testing"'
eval echo '${'$H'[1]}'
echo ${boats[1]}

Thing is, that eval ends up running a sub shell so it probably won't be real fast to assign 500 arrays of 10-15 items each.

Another thing you could try and do is write out a whole head of assign statements to a file and then source it into the current shell

H=fish
echo $H'[1]="carp"' > /tmp/asgn_$$
echo $H'[2]="cod"' >> /tmp/asgn_$$
echo $H'[3]="marlin"' >> /tmp/asgn_$$
 
. /tmp/asgn_$$
rm -f /tmp/asgn_$$
 
echo ${fish[2]}