[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Aw: Re: currently doable? Indirect notation used w/a hash
From: |
Dan Douglas |
Subject: |
Re: Aw: Re: currently doable? Indirect notation used w/a hash |
Date: |
Tue, 18 Jun 2013 20:35:22 -0500 |
User-agent: |
KMail/4.10.4 (Linux/3.9.5-pf+; KDE/4.10.4; x86_64; ; ) |
On Monday, June 17, 2013 02:33:09 PM John Kearney wrote:
> Like I said its a back door aproach, it circumvents the parser. which
> doesn't allow this syntax
> ${${Name}[1]}
> I didn't actually find this myself it was reproted on this list a long
> time ago. I do remember Chet saying he wouldn't break it. But other
> than that I can't remember the discussion all that well. As always with
> this topic it was a pretty lively debate.
>
>
> Yhea its a constant fight getting my email clients to stop
> capitialising various things in code.
>
> Gesendet: Montag, 17. Juni 2013 um 13:57 Uhr
> Von: "Greg Wooledge" <wooledg@eeg.ccf.org>
> An: "Linda Walsh" <bash@tlinx.org>
> Cc: "John Kearney" <dethrophes@web.de>, bug-bash <bug-bash@gnu.org>
> Betreff: Re: currently doable? Indirect notation used w/a hash
> On Sat, Jun 15, 2013 at 12:36:22PM -0700, Linda Walsh wrote:
> > John Kearney wrote:
> > >There is also a backdoor approach that I don't really advise.
> > >val="${ArrayName}[Index]"
> > >echo "${!val}"
> > -----
> > Don't advise? Any particular reason? or stylistic?
> I'd shared this advice ("don't use it"), because I cannot for the
> life of me tell whether this is a bug or a feature. As near as I
> can tell, it is an unforeseen consequence of the parser implementation,
> not documented anywhere. As such, I would not rely on it to continue
> working in future Bash releases.
> P.S. you meant printf -v, not -V.
This has been discussed many times before but I'll say again that this is
consistent with almost every mechanism that accepts variable names in Bash. I
would be very surprised if the exact same code wasn't used for evaluating
parameter names (and their subscripts) because even the little quirks are
consistent nearly everywhere.
Oh look, Bash supports multi-dimensional arrays:
#!/usr/bin/env bash
function getElem {
while
[[ ${!1+_} ]] || return 1
typeset -a "__getElemArr=${!1}"
set -- "__getElemArr${1#*]}"
[[ $1 == *\[!(@]|\*]) ]]
do :
done
printf '<%s> ' "${!1}"
echo
}
a=( '(a b c)' $'([3]=\'(d e f)\' [5]=1 2 3)' '(g h i)' )
# typeset -a a=(([0]=a [1]=b [2]=c) ([3]=([0]=d [1]=e [2]=f) [5]=1 [6]=2 [7]=3)
([0]=g [1]=h [2]=i) )
getElem 'a[1][3][@]' || echo unset
--
Dan Douglas
Aw: currently doable? Indirect notation used w/a hash, John Kearney, 2013/06/15