PDA

View Full Version : bash script -->> arrays, Indirect Variable References--->> help :)


niekshas
25th June 2008, 16:34
#well ihawe something like this

Array=(first second)

firstoption=(one two)

secondoption=(11 22)

#now i'm reading like this

For segment in "${Array[@]}"; do
x=$segment"option" #i'm geing something like firstoption
eval t=\${$x[@]} #I hope that t will be array
For opt in "${t[@]}"
echo opt
done
done

###############

well i hope read like all options... but cant... couse t hawe only one value "one two" or "11 22 "
i cnow thats LAME so i'm asking... how i can improve this script ???

burschik
30th June 2008, 13:35
Array=(first second)

firstoption=(one two)

secondoption=(11 22)

#now i'm reading like this

for segment in "${Array[@]}"; do
x=$segment"option"
eval t=\${$x[@]}
for opt in ${t}; do
echo $opt
done
done

burschik
1st July 2008, 14:18
Array=(first second)

firstoption=(one two)

secondoption=(11 22)

for segment in ${Array[@]}; do
x=${segment}option
eval t=(\${$x[@]})
for opt in ${t[@]}; do
echo $opt
done
done