bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Syntax Question...


From: Linda Walsh
Subject: Re: Syntax Question...
Date: Sat, 13 Aug 2011 21:51:20 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666




` Dennis Williamson wrote:
On Sat, Aug 13, 2011 at 6:41 PM, Linda Walsh <bash@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

[Prev in Thread] Current Thread [Next in Thread]