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


Groups > gnu.bash.bug > #14398

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

From Grisha Levit <grishalevit@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: delcare -a on a nameref in a function modifies nameref instead of target
Date 2018-07-25 16:27 -0400
Message-ID <mailman.4218.1532550468.1292.bug-bash@gnu.org> (permalink)
References <CAMu=BrqTimtENjRABPgRdDhn5bQG2zBMv5YfQsNQDETh6oAjeQ@mail.gmail.com>

Show all headers | View raw


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"

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web