Two things, first this is my first question in this forum and I do apologise if the formating is all over the place. Second I have not written that many bash scripts, and it tend to be quite a long time between the scripts I produce.
That said, here is my question.
Is it possible to do something like this in bash (Clear array $array contains):
$array=()
Basically this is what I would like to do. I have a variable with array variable names in it:
array1=()
array2=()
arrayList="array1 array2"
# In a function far far away
for array in $arrayList
do
eval arr=("\"\${$array[@]\"")
for index in ${!arr[@]}
do
echo "${arr[$index]}"
done
# Here is the big "?", I like to clear the array that $array refers to.
$array=()
done
My arrays contain strings that include "" (space) and this is why I use the eval statement. Not sure it's needed but at least it's working. The script is more or less working as I want it too, but I need to clear the arrays in the $arrayList, and I rather not hardcode it somewhere, even though that would be easy.
evalis not a recommended way to go since you can inject bad stuff in it, or even do some stupid stuff yourself if not careful what youevel. I will consider swaping it for another solution, even though this script will only be used by myself.