Op 05-03-18 om 13:57 schreef Greg Wooledge: > On Sat, Mar 03, 2018 at 08:24:06PM +0900, Koichi Murase wrote: >> - Note: ksh seems not support local variables. "typeset" in function >> scopes defines a global variable, and "unset" removes the global >> variable. > > "Real ksh" has two different kinds of functions -- ones declared with > "foo()" and ones declared with "function foo". They have different > treatment of local variables, and the ksh man page does not clearly > (at least to me) describe the difference.
You have to distinguish between two kinds of ksh here. In the old "real ksh", AT&T ksh88 (which is closed source and only in current use as /usr/xpg4/bin/sh on Solaris), functions defined with "foo()" and with "function foo" have identical behaviour with regards to local variables. They have dynamic scoping, that is, if x calls y, then y has access to x's local variables. This is the model that every other current shell, including bash, emulates -- each with its own particular set of quirks and gotchas, of course. That includes the "ksh clones" (pdksh, mksh, et al) which are all ksh88 clones. In the current "real ksh", AT&T ksh93, things changed in radical and incompatible ways. Functions defined with "foo()" don't have local variables at all. Functions defined with "function foo" have a new model for local variables: static scoping. That is, if x calls y, then y does *not* have access to x's local variables. In static scoping, "unset" in a local scope can never influence the global scope. No other shell to date has emulated the ksh93 model. HTH, - M.