Artificial intelligent assistant

How to unset a variable set with declare in bash Suppose I have the following: foo=hello declare -n bar=foo echo $bar # hello Cool. Now I want to undeclare `bar`. unset bar declare -p bar # declare -n v="foo" declare -p foo # bash: declare: foo: not found How do I unset a variable created with `declare -n`?

As is often the case, Stack Exchange did an excellent job rubber-ducking, and I found the solution.


foo=hello
declare -n v=foo

unset -n v # <-- here's the magic

declare -p v
# bash: declare: v: not found
declare -p foo
# declare -- foo="hello"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 58b14e8898a6f3e5c2522168dc610bc3