[Top][All Lists]

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

[Help-bash] indirection for arrays

From: Bill Gradwohl
Subject: [Help-bash] indirection for arrays
Date: Sat, 5 May 2012 14:16:36 -0600

Via a web site reference, Dan Douglas (Thank You) provided something akin to this:

func() {
    local -a 'keys=("${!'"$1"'address@hidden")' 

declare -a myArray=(1 2 3)

func 'myArray'

Neat trick! Took me a while to figure out how it works. The single quotes in particular stopped me in my tracks for a while.

Can I rely on this in future versions of bash, or is this a side effect that might disappear some day? I can find no documentation that says specifically it's supported.

Also, since indirection requires the ! immediately after a {, this means indirection can never be on the left hand side of an assignment. Correct?

The "trick" above is doing a type of indirection by getting the parser to cooperate in a sneaky fashion. At least that's my analysis.

Is there some other mechanism ("trick") besides eval that can do indirection on the left hand side of an assignment? A mechanism that can be relied on in future releases.

Bill Gradwohl

reply via email to

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