Hi folks,
A really dumb question as I've wasted far too long trying to get this to work.... (on RH bash)
I have an array:
m0[1]='<hello>'
m0[2]='<there>'
m0[3]='<fred>'
v0[1]='<goodbye>'
v0[2]='<again>'
v0[3]='<john>'
in my code I calculate the value of the variable to output and if I echo it, I get m0 or v0, but if I try and print the variable, I either get 3 as an output, or bad variable substitution, or no output.
# $oc evaluates to m0 or v0
eval "printf '%s\n' \"\${#${oc}[@]}\"" (displays 3 as output)
#printf -- '%s\n' "${m0[@]}" (displays correctly (when uncommented) but was just a test)
printf -- '%s\n' "${oc[@]}" (no output)
printf -- '%s\n' "${$oc[@]}" (bad variable substitution)
Thanks in advance - and apologies for the very basic question.