#613556 Why dash's local variable inherits its value from outter env?

Package:
dash
Source:
dash
Description:
POSIX-compliant shell
Submitter:
weakish
Date:
2015-11-20 18:33:07 UTC
Severity:
important
Tags:
#613556#5
Date:
2011-02-15 16:40:31 UTC
From:
To:
Given the following script:

f() {
  local x
    x='f'
    g() {
      local x
        echo $x
    }
  g
}

f


pdksh, mksh and bash give the expected output, since x is not set in
g().

dash gives this 'f'

According to man dash:

When a variable is made local, it inherits the initial value and
exported and readonly flags from the variable with the same
name in the surrounding scope, if there is one.

Why does dash implement this feature?  I guess sinec local is not specified
by POSIX, there isn't any history issues here.

#613556#10
Date:
2011-02-15 19:44:25 UTC
From:
To:
Why do you consider it a bug? policy specifically says:

It's simply an unspecified behaviour, just initialize it to the empty value.
E.g. local x=

Cheers,

#613556#15
Date:
2011-02-15 20:05:11 UTC
From:
To:
severity 613556 wishlist
tags 613556 + upstream wontfix
quit

Hi,

weakish wrote:

When there's no reason to behave otherwise, dash follows the
historical dash and ash behaviors, to give existing users a smooth
upgrade path.  The original ash[1] follows the behavior you
described.

	When a variable is made local, it inherits the
	initial value and exported and readonly flags from
	the variable with the same name in the surrounding
	scope, if there is one.  Otherwise, the variable is
	initially unset.

The Austin Group is considering[2] specifying a "typeset" keyword
somewhat like local (but lexically scoped, maybe).  If you have ideas
for what that should look like, feel free to get in touch with Eric
Blake and the Austin Group[3] list.

Kind regards,
Jonathan

[1] http://groups.google.com/group/comp.sources.unix/msg/2774e7653a8e6274
[2] http://thread.gmane.org/gmane.comp.shells.zsh.devel/21342
[3] http://www.opengroup.org/austin/

#613556#24
Date:
2011-02-16 14:06:48 UTC
From:
To:
I see. Thanks for pointing out.
#613556#29
Date:
2011-02-16 14:11:21 UTC
From:
To:
Sorry for tag it as a bug before.
I just thought that dash's behavior is different from all other shell
I've encountered.
I now understood this behavior is from ash.