bug-bash
[Top][All Lists]
Advanced

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

Re: Changing the way bash expands associative array subscripts


From: Greg Wooledge
Subject: Re: Changing the way bash expands associative array subscripts
Date: Thu, 8 Apr 2021 16:06:23 -0400

On Thu, Apr 08, 2021 at 03:37:33PM -0400, Chet Ramey wrote:
> On 4/6/21 1:42 PM, Greg Wooledge wrote:
> > That said, the fact that you can put 'a[@]' in an indirect variable and
> > get an array expansion out of "${!x}" is completely repulsive to me.
> 
> What do you think should happen?

What I would have expected originally: an error message and a non-zero
exit status.

But apparently someone stumbled upon this trick, and passed it around,
and now there's a whole subculture of people who use this as a hack for
trying to pass array variables to functions by reference.  (This hack
predates declare -n.)

So now I'm not advocating for any change to it.  It would break too
many scripts.  I can only advise people to start using declare -n
instead, with additional warnings about variable name scoping and
collisions (which are also problems with the indirection hack, or with
eval-based hacks).



reply via email to

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