I am pretty new to bash scripting and just gather all the information I needed for my script.
I want to iterate through an array with a variable name. My script so far:
#!/bin/bash
declare -a bff=("Abnehmen" "Buecher" "Dating" "Dating" "Fitness" "Handy" "Hunde" "Reisen" "Schmuck" "Schwanger" "Uhren")
declare -a dab=("baby" "beauty" "fitness" "haushalt" "heimwekren")
for product in bff dab; do
echo "${product[@]}" #works fine, it echoes 'bff' in the first loop
for sub in ${!product[@]}; do
echo "${product}/${sub}" #does not work, echoes 'bff/0'
done
done
Output:
bff
bff/0
dab
dab/0
ddb
ddb/0
dwb
dwb/0
pod
pod/0
I don't udnerstand why I can echo the variable correctly, but can't use it in the for loop. The tutorial I've found were only about echoing the varibale variable, but now how to use it in a loop.
Could anyone assist me here or guide me in the correct direction?
My desired output would be:
bff
bff/Abnehmen
bff/Buecher
bff/Dating
...
dab
dab/baby
dab/beauty
...
echo bff; printf 'bff/%s\n' ${bff[@]}; echo dab; printf 'dab/%s\n' ${dab[@]};
?