Re: OT: Bash arrays & indirection?

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

 



On 16 February 2012 15:41, Patrick Lists <fedora-list@xxxxxxxxxxxxxxxxx> wrote:
> On 16-02-12 12:13, Ian Malone wrote:
>>
>> On 16 February 2012 08:43, Patrick Lists<fedora-list@xxxxxxxxxxxxxxxxx>
>>  wrote:
>>>
>>> Hi,
>>>
>>> I am trying to do the following in bash:
>>>
>>> OPTIONS = ( alfa beta gamma )
>>> SUBOPTIONS_alfa = ( alfa0 alfa1 )
>>> count=0
>>> SETCOUNT = ${#SUBOPTIONS_${OPTIONS[$count]}[@]}
>>>

>> nameSUBOPTS=SUBOPTIONS_${OPTIONS[$count]}[@]
>> tmpARR=(${!nameSUBOPTS}) #You need tmpARR, because the '#' expansion
>> wont work with '!'
>> SETCOUNT=${#tmpARR[@]}
>> echo ${OPTIONS[$count]}:$SETCOUNT
>> done
>
>
> Thanks! I will try it out. It looks more sane that what I found myself which
> apparently is challenging the bash gods to unleash their wrath if I use it:
>
> eval SETCOUNT=\${#SUBOPTIONS_${OPTIONS[$count]}[@]}
>

Yes, I'd meant to mention you could always use eval, but the quoting
introduced by each additional layer of indirection will eventually
cause brain damage.

>> Finally, it's spelt 'alpha' ;)
>
>
> Heh spelt or spelled? :)

Universal law of pedantry in action...

-- 
imalone
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux