Hi Thorsten,

A customer of ours has reported the following difference in behavior
between mksh and ksh-93: unsetting a local variable causes mksh to
destroy that local variable, so any further reference to its name will
relate to the global variable by the same name. Example:

#!/bin/ksh

function func2
{
        typeset foo

        unset foo
        foo=2
}

foo=42
func2
echo "foo=$foo"

mksh will print 2, while ksh-93 will print 42. Note that bash will
print 42 as well, and so does dash after adjusting the shell syntax so
that dash understands it. So it seems that mksh handles this case
differently from all other shells.

I looked at the POSIX standard [1] but as I understand it POSIX doesn't
support local variables in the first place so the described behavior of
"unset" clearly refers to global variables and is subject to
interpretation for local variables.

I see that one can use "unset foo[*]" in mksh to achieve the "unset
foo" of other shells. I guess this is a side effect of the
impossibility to preserve the variable attributes without preserving
the variable itself. But this doesn't really help anyway, as this
syntax is not portable.

So, is the behavior of unset on local variables a design decision, or
an overlook?

[1] http://pubs.opengroup.org/onlinepubs/009695399/utilities/unset.html

Thanks,
-- 
Jean Delvare
SUSE L3 Support

Reply via email to