cc: [email protected]
Subject: Re: [ast-users] function variable heritage
--------
> Hi,
>
> just discovered that this seems to not working anymore, is this a bug ?
>
> $ cat << \EOF > /tmp/foobar
> function foo {
> x=1
> }
> function bar {
> typeset x=0
> foo
> echo $x
> }
> bar
> EOF
>
This is not a bug.
ksh93 uses static scoping just like C.
In C you would not expect the auto variable x defined bar to be visible on foo.
The x in foo refers to a global variable.
Now you could pass x as an environment variable from bar to foo bug calling
foo as
x=$x foo
However, this creates a new variable x in bar.
To get the behavior you have with x being shared, pass x as a name reference:
foo x
and then in bar
typeset x=$1
This changed 20 years ago and is listed in the differences between ksh88
and ks93.
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users