On 03/14/2017 05:08 AM, Jean Delvare wrote:
> So internally bash does make a difference between a variable being
> null and a variable being unset. A bash variable can actually have 4
> distinct states: non-existent, existent but unset, set but null, and
> non-null. "typeset", "local" and "unset" all put the variable into
> state "existent but unset" (unlike mksh.)

It depends on context and the type of variable involved. Arrays complicate
things and namerefs _really_ complicate things. In bash, declaring a
simple local scalar, assigning it a value, then unsettling it within
the same scope brings the variable back to the same "hidden local"
state it is in when declared local but not given a value. However,
unsetting the local from a child scope does fully destroy the local,
uncovering the variables in parent scopes.

Thus bash's is actually the most flexible of the dynamic scope systems
in some ways. If you want bash to behave like mksh just define a wrapper
function for unset (I usually name it `unset2'). Contrast with zsh,
which has no way to unset a local (last I checked, which was years
ago). In addition, bash has `declare -g' for directly acting on the
global scope. It has a few good uses e.g. for setting special variables
like PATH or LC_*.

Reply via email to