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: Thu, 18 Aug 2011 07:13:42 -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




Pierre Gaston wrote:
On Mon, Aug 15, 2011 at 2:31 AM, Linda Walsh <address@hidden> wrote:
Re:   BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006
Pierre Gaston wrote:
Linda:
please show quote the section
that shows using an variable that holds the name of an array to be used (and 
assigned to)....  else ..
The proof is in the faq, you could have found it if you were not busy
trolling the list.
====
Guess this was not possible.  The FAQ covers indirect,
it covers arrays, but I see no place where it covers the combination.
If you see such, then quote it.  Don't just wave your arms around
making unsubstantiated claims or accusations.

I didn't ask for the impossible -- just a quote.

Apparently that was too much to ask for, so you call me a troll
....ya, right. Who's the troll?

 # Bash -- trick #1.  Seems to work in bash 2 and up.
 realarray=(...) ref=realarray; index=2
 tmp="$ref[$index]"
 echo "${!tmp}"            # gives array element [2]
----

Ok I'll give you credit for, being serious in believing the page answered
my qustion....

But my question was: what was the syntax to do: to use an
indirect array reference directly to reference members of the array, as
indicated in my failed example:

 echo ${#${!name}[*]}
bash: ${#${!name}[*]}: bad substitution
# note that ${#<arrname>[*(or @)]} will give you the num elements in
the array.    I wanted to sub in '${!var} for 'arrname' in order to

---
Michael Witten, immediate got the issues I was trying to avoid and responded:

It's probably what you're trying to avoid, but you'll probably have to
construct and then eval the right code by hand:

 $(eval "echo \${#$name[*]}")
----
        I was trying to avoid any workaround that used
one or more multiple common workarounds like evals and/or
use of tmp vars... I.e.  I saw no such syntax.

         As others confirmed: such syntax is NOT
possible in the current bash. It was in the context of that, when you indicated there was an answer to my
  'how to do syntax for xxyz'

on the page in question and thus my need to have
you explain what you meant (via a quote showing the
use of such).

I now understand that you thought such a response would suffice. Perhaps you also understand
why that's not what I was looking for.

*peace*
linda






reply via email to

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