bug-bash
[Top][All Lists]
Advanced

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

nameref bug?


From: lolilolicon
Subject: nameref bug?
Date: Sat, 30 Aug 2014 11:19:11 +0800

The following is my test scripts and their output.
They are very similar, and I do not think they should result in
different output.
The output I expected from all of them is:

v1
v2

But as you can see, only 1 in the following 4 cases does it meet my
expectation. In the other 3 cases, the nameref attribute of the variable
'ref' is lost unexpectedly.

=== script ===
#!/bin/bash
declare -a arr=('dict[k1]' 'dict[k2]')
declare -A dict='([k1]=v1 [k2]=v2)'
func() {
  local -i i
  for ((i=0; i<address@hidden; ++i)); do
    local -n ref
    ref=${arr[i]}
    echo $ref
  done
}
func

--- output ---
v1
v2


=== script ===
#!/bin/bash
declare -a arr=('dict[k1]' 'dict[k2]')
declare -A dict='([k1]=v1 [k2]=v2)'
func() {
  local -i i
  local -n ref
  for ((i=0; i<address@hidden; ++i)); do
    ref=${arr[i]}
    echo $ref
  done
}
func

--- output ---
v1
dict[k2]


=== script ===
#!/bin/bash
declare -a arr=('dict[k1]' 'dict[k2]')
declare -A dict='([k1]=v1 [k2]=v2)'
declare -i i
for ((i=0; i<address@hidden; ++i)); do
  declare -n ref
  ref=${arr[i]}
  echo $ref
done

--- output ---
v1
dict[k2]


=== script ===
#!/bin/bash
declare -a arr=('dict[k1]' 'dict[k2]')
declare -A dict='([k1]=v1 [k2]=v2)'
declare -i i
declare -n ref
for ((i=0; i<address@hidden; ++i)); do
  ref=${arr[i]}
  echo $ref
done

--- output ---
v1
dict[k2]



reply via email to

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