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

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
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 Wed, 25 Jul 2018 16:27:27 -0400
Lines 25
Approved bug-bash@gnu.org
Message-ID <mailman.4218.1532550468.1292.bug-bash@gnu.org> (permalink)
References <CAMu=BrqTimtENjRABPgRdDhn5bQG2zBMv5YfQsNQDETh6oAjeQ@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1532550468 12905 208.118.235.17 (25 Jul 2018 20:27:48 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash <bug-bash@gnu.org>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=7uTTjlYNQofZgRkp9fkpM1CXiWiHn6HuFO5qvoAyQjQ=; b=FTDsR9zL4qCyTBgOGsdPD4cXRdBA/eGmeZUCU84AUWOPmFXwpW6j09x8U/UaNjK5Nf 9aEPiztG43H40s6dRLz31yB58Ca4h9GiwCt0wX3Wa+nEjo/VvSO7PWOWhCwmO6hdBFW/ 3S2zyNz9Lh89yEQf2q9VuZ5DrL5OzMNcLRMzUx4I7+wh/aGXj2Bde+2MaRQ5CGSdGAHX vZgje/E3geGb1h6myAzQsqtmY6g4atvYsOdn6TU8HnJAf/2VgzEKvbFMU+rjHbHvgboR 88VJPHO2rIT5lqe7sad0l8EZWil42m4vYAZRgOpglK4EWpAZY3efscXIaa4dJpHW33+2 Y3Ow==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=7uTTjlYNQofZgRkp9fkpM1CXiWiHn6HuFO5qvoAyQjQ=; b=HZG8xO+typKXSGidTqAm377r/5MDTo87LMghKh+A9tOghfgBIG729AC0IhlclQEPlU 6w9d3pJblidw21+wzuT16B4Yg3ZKhqM1OG0bToN9pu1UU7jqLNPUOCkKfIusZyiO1NP1 I2RBa7dnnvW2KHdZpgFpz+TT+vS7JJ8NlIqmwi0zsx50yOM2iNfhqPmKunSHPJl1K1hi mdn7854eJwjHXeRfabgjbTsfoECRvmzfZrXO94xovTqnZTxDay8NHJvqtJT05cMCmzvV tA3LBfYiEcuHpfrxkgTSVq3NoWaslLLvcRL9iesnBxR5NfA2Wfjrj1gkV5IujqIPuMOF WQXQ==
X-Gm-Message-State AOUpUlEQCX+st1zOQij4SFvgBQ9pwvHchiBa/bC65CmBJJKrfQBI5q0Q xilFyst5Bb8xMURH8rHuTYYEKAg9TIjIeq3Grn95rQNuPnur4g==
X-Google-Smtp-Source AAOMgpdB9ZLX3HIbBuGJrQ9/W2J8jXpGyx4LQFE6+rIl97slTYRgJb+tjQQrIZ25gQCMXDwgiRqEUDps4VidKtbdsT0=
X-Received by 2002:a19:eac1:: with SMTP id y62-v6mr14218767lfi.138.1532550458622; Wed, 25 Jul 2018 13:27:38 -0700 (PDT)
In-Reply-To <CAMu=BrqTimtENjRABPgRdDhn5bQG2zBMv5YfQsNQDETh6oAjeQ@mail.gmail.com>
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2a00:1450:4864:20::134
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14398

Show key headers only | 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