On 4/28/16 9:49 PM, Grisha Levit wrote:
> In a slightly different version, with `declare -n r; r=a', the function
> exits with code 1 after the `r=a' statement:
>
> $ declare -nt r=a; f() { declare a; declare -n r; r=a; declare -p a r; };
> f; echo $?
> 1
In this case, you create a self-referencing local nameref, which ends up
resolving to nothing, which causes an assignment error, which results in
function execution being aborted. You create the self-referencing local
nameref because bash follows the nameref chain for `r', and resolves it
to `a'. It's as Piotr surmised: as if you ran `typeset -n a; a=a'.
When asked to create a local variable that shadows a nameref from a
different context, declare needs to throw away the results of that nameref
chain search and just create a local variable.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/