` Dennis Williamson wrote:
On Sat, Aug 13, 2011 at 6:41 PM, Linda Walsh <b...@tlinx.org> wrote:
I have to use 'indirect' syntax:     ${!name}
But that doesn't seem to play well with array syntax:
${#${!name}[*]}    #  bash: ${#${!name}[*]}: bad substitution

What syntax would I use for this?

Please read BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006
I looked at the page....read every section that was >basic & some basic...

nothing about using indirect variables with arrays... (let alone assigning to them)..

Still had to use an eval for assigning...

Also his page misses a really easy way to do indirect assignment for integer vars:


 b=1
 a=b
 (($a=23))
 echo $b
23
---
It's good to know how to do that w/string-vars in 1 line too (i.e.):

 ref=line
 read $ref<<<$(echo "my string")
 echo $line
hi there

-- but I wouldn't have known or thought of that w/out reading that
page (which only demo's the <<herestring form)....

But I've been using <<<$() all the time for multi-var assignments ever
since Chet graciously answered my question about multi-var assignment
on the list a few months back...


read a b c<<<$(echo one two three)


I betcha indirects would work there too...  (i.e. could do multiple indirect
assignments in 1 statement...)...


thanks for the ptr...but still looks like it's eval for me...even after my
code simplification...though I should bench the diff
between

eval "$a=xxx"
and
read $a<<<(echo "xxx")








Reply via email to