Using dynamic arrays to extract the values

Hi all,
We have requirement to generate load timing based on subject areas HOUSEHOLD, BANKING and TRADING. These values are stored in an array SUB_ARR

SUB_ARR=("HOUSEHOLD" "BANKING" "TRADING")

Based on indicator files produced while processing data for each type, we need to get the stats (using stats -c "%y") of when file was generated. These file names are again stored in array.

HOUSEHOLD_LIST=("HH1_FILE" "HH2_FILE" "HH3_FILE" "HH4_FILE")

similalry BANKING_LIST and TRADING_LIST

my requirement is dynamically fetch the values of LIST for each SUB_ARR value as below :

for i in ${SUB_ARR[@]}
do
  SUB_LIST=$i'_LIST'   
  <next_code_lines>
done

In next code lines, now my requirement is to fetch the values for <SUB>_LIST and assign it to variables.
eg for first iteration
SUB_LIST=$i'_LIST' would be HOUSEHOLD_LIST.
now i want to extract the value of HOUSEHOLD_LIST[0] and assign it to a varaible by modifying SUB_LIST in some way.
I tried out many ways but unsuccessful.

Would someone please provide any assistance?
Any help is apprecated.

Thanks
Sam

Something like this?

for i in ${SUB_ARR[@]}
do
  SUB_LIST=$i'_LIST'
  for j in $(eval echo \${$SUB_LIST[@]})
  do
    echo $j
  done
done

HTH
--ahamed

1 Like

THIS WAS INDEED HELPFUL