bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

declare [-+]n behavior on existing (chained) namerefs


From: Grisha Levit
Subject: declare [-+]n behavior on existing (chained) namerefs
Date: Wed, 27 Apr 2016 15:26:04 -0400

declare -n name=value, when name is already a nameref, shows the following presumably inconsistent behavior:

Given a chain of namerefs like:

ref_1 -> ref_2 -> ... -> ref_i ... -> ref_N [-> var]

For example, starting with:

unset -n ref{1..3}
declare -n ref1=ref2 ref2=ref3 ref3=var1
# declare -n ref1=var2
# declare -p ref{1..4}
declare -n ref1="ref2"   # unchanged
declare -n ref2="ref3"
declare -n ref3="var2"   # changed
# declare +n ref1
# declare -p ref{1..3}
declare -n ref1="ref2"   # unchanged
declare -n ref2="ref3"
declare -- ref3="var1"   # changed, no loner nameref

Or alternatively:

unset -n ref{1..3}
declare -n ref1=ref2 ref2=ref3 ref3
# declare +n ref1
# declare -p ref{1..3}
declare -n ref1="ref2"   # unchanged
declare -n ref2="ref3"   # unchanged
declare -n ref3          # unchanged
# declare -n ref1=var1
# declare -p ref{1..3}
declare -n ref1="ref2"
declare -n ref2="ref3"
declare -n ref3

The man page says:

All references, assignments, and attribute modifications to name, except for changing the -n attribute itself, are performed on the variable referenced by name’s value.

This does not appear to be the case, as declare -n ref_N=value changes $ref_N, not $value, and declare +n ref_i changes ref_N.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]