Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14398 > unrolled thread

Re: delcare -a on a nameref in a function modifies nameref instead of target

Started byGrisha Levit <grishalevit@gmail.com>
First post2018-07-25 16:27 -0400
Last post2018-07-25 16:27 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: delcare -a on a nameref in a function modifies nameref instead of target Grisha Levit <grishalevit@gmail.com> - 2018-07-25 16:27 -0400

#14398 — Re: delcare -a on a nameref in a function modifies nameref instead of target

FromGrisha Levit <grishalevit@gmail.com>
Date2018-07-25 16:27 -0400
SubjectRe: delcare -a on a nameref in a function modifies nameref instead of target
Message-ID<mailman.4218.1532550468.1292.bug-bash@gnu.org>
In the latest devel this issue is fixed for the case that the local nameref
points to a non-existent variable but there is still a bug if the variable
pointed to by a local nameref already exists.  In such a case, `declare'
commands after the initial `declare -n' end up modifying the value and/or
attributes of the local nameref variable itself rather than modifying the
target of the nameref.

At global scope:

    unset -n ref; unset var
    declare var=X; declare -n ref=var; declare ref=(Y); declare -p ref var

    declare -n ref="var"
    declare -a var=([0]="Y")

Whereas in a function:

    unset -n ref; unset var
    f() {
        declare var=X; declare -n ref=var; declare ref=(Y); declare -p ref var
    }; f

    declare -an ref=([0]="Y")
    declare -- var="X"

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web