bug-bash
[Top][All Lists]
Advanced

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

Re: Global variable modification by nameref chain


From: Chet Ramey
Subject: Re: Global variable modification by nameref chain
Date: Sun, 22 May 2016 22:08:09 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.0

On 5/22/16 6:06 PM, Grisha Levit wrote:

> 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:

That was the original intent, but I am now reconsidering it.  ksh93 doesn't
seem to allow nameref self-references at all, and I am thinking about
whether or not that is the best way to avoid problems like this.

> |$ ref=; add_X ref; echo "$ref" X |
> 
> 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 X |

Should the assignment work?  I'm considering changing the assignments to
work more like the references.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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