I'm not sure I get what you meant, but maybe this can help you :
one=( "one" 5 6 7 8 )
two=( "two" 11 22 33 )
three=( "tree" 777 888 999 )
all=( one two three )
for i in ${all[*]}; do
ref=$i[@];
for j in ${!ref}; do
echo $j
done
done
one
5
6
7
8
two
11
22
33
tree
777
888
999
manpreet
Best Answer
2 years ago
I'm using rsync to copy specific files from a source directory (and subdirectories) to a destination directory (and subdirectories). The mapping of the subdirectories is not identical, so I'm defining arrays of subdirectories of the destination directory that contain the source file paths.
I've been unable to successfully loop over the destination arrays with access to the names of the arrays. Here's a MWE (filenames and directories must be edited, obviously).
This is obviously wrong because I don't want the destination to be the contents of
$destsubdir
but the name of the variable itself. I've been unable to successfully achieve this.Note that a proper solution would allow any number of arrays to included without restructuring (e.g. no extra for-loops).
If multi-indexed arrays were possible in bash, this would be much easier, I think. Thanks for any help!
Solution
@jeanrjc has a good solution. Here's what it looks like in terms of my example above.