[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] indirection for arrays
From: |
Dan Douglas |
Subject: |
Re: [Help-bash] indirection for arrays |
Date: |
Wed, 09 May 2012 02:42:34 -0500 |
User-agent: |
KMail/4.8.3 (Linux/3.3.4-pf+; KDE/4.8.3; x86_64; ; ) |
On Monday, May 07, 2012 08:22:51 AM Greg Wooledge wrote:
> On Sat, May 05, 2012 at 02:16:36PM -0600, Bill Gradwohl wrote:
> > Via a web site reference, Dan Douglas (Thank You) provided something akin
> > to this:
> >
> > func() {
> >
> > local -a 'keys=("${!'"$1"'address@hidden")'
>
> It burns!!
>
> > declare -a myArray=(1 2 3)
> >
> > func 'myArray'
>
> For the love of god, if you want to pass arrays to a function by name,
> use ksh93, not bash.
Good advice. (unfortunately not always an option).
> UNTIL SUCH TIME as bash has a feature like this, you cannot do this in
> bash. Throwing dozens of random punctuation characters at the screen
> until the code appears to do what you think it should do is not sane.
Not random. The same behavior affects this more common construct:
~ $ x=y; y=(1 2 3); declare -a "$x"+=(a b c); declare -p y
-bash: syntax error near unexpected token `('
One would need to know that this triggers declare to treat args as ordinary
args and to quote the entire thing as such.
And it isn't limited to declare - eval does it too:
$ eval x=(1 2 3); declare -p x
declare -a x='([0]="1" [1]="2" [2]="3")'
But this might be a bug since presumably eval always takes ordinary arguments,
and ignores the metacharacters in this special case for some reason.
--
Dan Douglas
signature.asc
Description: This is a digitally signed message part.
- [Help-bash] indirection for arrays, Bill Gradwohl, 2012/05/05
- Re: [Help-bash] indirection for arrays, John Kearney, 2012/05/05
- Re: [Help-bash] indirection for arrays, Dan Douglas, 2012/05/05
- Re: [Help-bash] indirection for arrays, Greg Wooledge, 2012/05/07
- Re: [Help-bash] indirection for arrays,
Dan Douglas <=
- Re: [Help-bash] indirection for arrays, Chet Ramey, 2012/05/09
- Re: [Help-bash] indirection for arrays, Dan Douglas, 2012/05/09