I am trying to understand the following part about unset
from https://unix.stackexchange.com/a/381782/674
unset
inbash
only unsets a variable if it has been declared in the current scope (leaves it declared though except in the global scope; it removes attributes and values and the variable is no longer array or hash; also note that on namerefs, it unsets the referenced variable). Otherwise, it just pops one variable layer from the stack mentioned above.
Bash manual doesn't mention anything related, or I miss it.
Could you explain with examples for
- "only unsets a variable if it has been declared in the current scope"
"leaves it declared though except in the global scope".
If
unset
a variable which is in a function's local scope, is theunset
variable not just unset but also undeclared?If
unset
a variable which is in the global scope, is theunset
variable just unset but still declared?How may I check if a variable is declared or not?
"Otherwise, it just pops one variable layer from the stack mentioned above."
What do "otherwise" and "one variable layer" mean?
Thanks.