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: konsolebox
Subject: Re: Changing the way bash expands associative array subscripts
Date: Fri, 9 Apr 2021 08:17:52 +0800

On Fri, Apr 9, 2021 at 4:08 AM Greg Wooledge <greg@wooledge.org> wrote:
> 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.)

It's not a hack since indirection allows references to:

1) Digit-based parameters ($1, $2, etc.)
2) Special variables (which includes $@)
3) Valid array references (array[@] and array[1 + 1] are one of them)
4) Legal identifiers

It's a definite shell feature despite lacking internal sanity checks.

-- 
konsolebox



reply via email to

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