I try to get a number of elements in an array, using dynamic array name.
I need the array name to be dynamic.
The array name is constructed as 'inf_ln_$nmb', where $nmb is a file line number
So, say I have the arr 'inf_ln_4':
> for (( el=0; el<${#inf_ln_4[*]}; el++ )); do
> echo "$el: >"${inf_ln_4[$el]}"<";
> done
0: >Address 2<
1: >Memphis, TN 38134<
2: ><
3: >31<
4: >11/1/2003<
5: >6/30/2004<
6: >00018906465 MAC 01<
7: >TRUE<
8: ><
9: ><
> # or :
> echo ${inf_ln_4[@]}
Address 2 Memphis, TN 38134 31 11/1/2003 6/30/2004 00018906465 MAC 01 TRUE
I do next:
>
>a=4; # this is to be used for dynamic array's name
> eval echo ${inf_ln_$a[@]} # expect 'eval' will replace $a for 4
bash: ${inf_ln_$a[@]}: bad substitution
>
> # the same I have by trying to access an array element:
> eval ec ${inf_ln_$a[0]}
bash: ${inf_ln_$a[0]}: bad substitution
Is there a way to prevent the bash-shell from treat the '$a[0]' as a substitution?
My main attempt is to copy the current dynamicaly numbered array to some staticly-named array to comfortably work with it's element
Appreciate your advise or help!
Alex