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.