Here's the updated list of cases: | r=/; declare -n r | declare -n r=/ | declare -n r; r=/ | declare -n r; for r in /; do :; done | declare -n r; select r in /; do :; done <<< 1; echo x; echo $r | declare -n r; ((r=0)) | ((r=0)); declare -n r | r=/ declare -n r | f() { declare -n r; }; r=/ f | f() { echo $r; }; declare -n r; r=/ f | declare -n r; : ${r:=/} | declare -n r; exec {r}>/dev/null | declare -n r; coproc r { :; }; echo $r | declare -r RO=x; r=$RO; declare -n r; x=y; declare -n RO; RO=z; declare -p RO; echo "$RO" | s=/; declare -n r=s; declare -n s; echo $r | declare -n r=s; declare -n s; s=/ | declare -n r; getopts x r -h | declare -n r; mapfile r < /dev/null | mapfile r < /dev/null; declare -n r | declare -n r; printf -v r /
You can set a nameref value to an invalid identifier, but what I noticed is that it will write the error message on *expansion* and not on assignment (this is what bash already does). The 'mapfile' one is interesting, because it drops the nameref attribute from the 'r' variable. -- Eduardo Bustamante https://dualbus.me/