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


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

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

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

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


Contents

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

#14356 — delcare -a on a nameref in a function modifies nameref instead of target

FromGrisha Levit <grishalevit@gmail.com>
Date2018-07-17 17:47 -0400
Subjectdelcare -a on a nameref in a function modifies nameref instead of target
Message-ID<mailman.3736.1531864056.1292.bug-bash@gnu.org>
At global scope this works as expected:

$ declare -n ref=var; declare -a ref=(X); declare -p ref var
declare -n ref="var"
declare -a var=([0]="X")

But in a function, we end up with the nameref variable having both the
`a' and `n' attributes and nothing in the target:

$ f() { declare -n ref=var; declare ref=(X); declare -p ref var; }; f
declare -an ref=([0]="X")
-bash: declare: var: not found

And a slight modification ends up modifying a global variable instead:

$  f() { declare -n ref=var; declare -a ref; ref=(X); declare -p ref
var; }; f; declare -p ref var
declare -an ref=()
-bash: declare: var: not found
declare -a ref=([0]="X")
-bash: declare: var: not found

[toc] | [standalone]


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


csiph-web