I am writing a bash script where I need to create arrays inside a for loop and name each array using the string contained in the counter (an array element) each iteration.
Here is the code:
Code:
myArray=( joe bob dave mark )
for k in "${myArray[@]}"
do
"$k_array"=( `cat fileUsedToPopulate.txt` )
done
# echo to test if one of the arrays has been created and populated
for j in "${joe_array[@]}"
do
echo $j
done
The desired result is 4 arrays, joe_array bob_array etc, each populated with the file.
However I haven't found anyway to escape the $k so that it appends to the array name when declaring/populating it.
Here is the error I am getting:
Code:
line 30: syntax error near unexpected token `cat fileUsedToPopulate.txt'
line 30: "$k_array"=(cat $DIR/$braDir/oem.txt` )'
Thanks for any help provided.