Description
Bash namerefs (local -n, typeset -n, declare -n) are not implemented. All 14 nameref tests are skipped.
Scope
local -n ref=var - create a nameref local variable
typeset -n ref / typeset +n ref - toggle nameref attribute
declare -n ref=var - declare nameref
- Reading through nameref:
echo $ref should dereference
- Writing through nameref:
ref=value should modify target
${!ref} with namerefs - inverted behavior (shows target name instead of dereferencing)
- Nameref chains:
ref1 -> ref2 -> var
- Nameref to array elements:
ref='arr[2]'
- Nameref via dynamic scoping in functions
unset ref should unset the target, not the ref
Repro
x=hello
declare -n ref=x
echo $ref
# bashkit outputs: x (wrong, should dereference to: hello)
ref=world
echo $x
# bashkit outputs: hello (wrong, should be: world — mutation through ref)
local -n arr_ref=myarr
myarr=(a b c)
echo ${arr_ref[1]}
# bashkit outputs: (empty) (wrong, should be: b)
Test coverage
14 skipped tests in crates/bashkit/tests/spec_cases/bash/nameref.test.sh (PR #351).
Oils reference: https://github.com/oilshell/oil/blob/master/spec/nameref.test.sh
Description
Bash namerefs (
local -n,typeset -n,declare -n) are not implemented. All 14 nameref tests are skipped.Scope
local -n ref=var- create a nameref local variabletypeset -n ref/typeset +n ref- toggle nameref attributedeclare -n ref=var- declare namerefecho $refshould dereferenceref=valueshould modify target${!ref}with namerefs - inverted behavior (shows target name instead of dereferencing)ref1 -> ref2 -> varref='arr[2]'unset refshould unset the target, not the refRepro
Test coverage
14 skipped tests in
crates/bashkit/tests/spec_cases/bash/nameref.test.sh(PR #351).Oils reference: https://github.com/oilshell/oil/blob/master/spec/nameref.test.sh