[Top][All Lists]

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

Re: Global variable modification by nameref chain

From: Grisha Levit
Subject: Re: Global variable modification by nameref chain
Date: Sun, 22 May 2016 18:06:33 -0400

The nameref resolution search doesn’t re-start back at the original context. It’s like a symbolic link — it continues at the same context as the resolved nameref.

If the assignment to the global variable is intentional, then shouldn’t expansion use the global variable’s value as well?

The expansion part really seems like the bug here, and can be demonstrated without any crazy cross-scope chains.

As I understand it, the intention is indeed to allow namerefs to point to outer-scope variables, even if they happen to have the same name as the reference, since a function like

add_X() { local -n ref=$1; ref+=X; }

works correctly even if it is passed ref as the argument:

$ ref=; add_X ref; echo "$ref"

However, if we try to access $ref inside the function, we get an error, though the += operation works just fine:

$ add_X_echo() { local -n ref=$1; ref+=X; echo "$ref"; }
$ ref=; add_X_echo; echo "$ref"
bash: warning: ref: circular name reference


reply via email to

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