sorry I should have provided a bit more detail before marking solved.
Initially I didn't actually solve my original issue I just reworked the script to avoid the situation.
However, I didn't give up and did in fact find the solution. Now I'll rework the script again because its a better implementation.
array1=("hello gus" "goodbye world" "I need help")
refarray1=array1
I started with above and wanted to know how to use refarray1 to refer to the elements in the array1.
The solution was to correctly deference refarray1. I was not getting that part correct.
These 2 for loops produce same output
# using array1
for((x=0; x < ${#array1[@]}; x += 1))
do
echo ${array1[$x]}
done
#using refarray
eval no_elem=\${#${refarray1}[@]}
for((x=0; x < $no_elem; x += 1))
do
eval echo \${${refarray1}[$x]}
done
the 2 for loops are equivalent. the second version is where I was stuck
Last edited by gusthecat; 03-07-2012 at 03:46 PM.
Reason: I hit submit by accident
|