I have a complex data structure in Bash like this:
Test1_Name="test 1"
Test1_Files=(
file01.txt
file02.txt
)
Test2_Name="test 2"
Test2_Files=(
file11.txt
file12.txt
)
TestNames="Test1 Test2"
In my improved script, I would like read the files from disk. Each test resides in a directory.
So I have a Bash snippet reading directories and reading all the file names. The result is present in an array: $Files[*].
How can I copy that array to an array prefixed with the test's name. Let's assume $TestName holds the test's name.
I know how to create a dynamically named array:
for $Name in $TestNames; do
declare -a "${TestName}_Files"
done
Will create e.g. Test1_Files and Test2_Files. The variables are of type array, because I used -a in declare.
But how can I copy $Files[*] to "${TestName}_Files" in such a loop?
I tried this:
declare -a "${TestName}_Files"=${Files[*]}
But it gives an error that =file01.txt is not a valid identifier.