cc: jonathan.anderson at sun.com
Subject: Re: [ksh93-integration-discuss] typeset -ix
--------

> Firstly, apologies if my question sounds dumb. I'm no expert in this field.
This is not a dumb question.  However, it is a documented difference between
ksh88 and ksh93.

ksh93 uses static scoping whereas ksh88 used dynamic scoping.
Thus, in the function do_add, the variable add is dymaically inherited
in ksh88 whereas it refers to the a global variable add.  Since add is
not defined in the global scope, its value is zero.

With ksh93, you can change do_add function by inserting the line
        nameref add=$1
and changing the call do
        do_add add

or you can just change the call to
        add=$add do_add
which will work for ksh93 and ksh88.
> 
> On s10, I had access to ksh scripts _like_:
> 
> function do_add {
>      add=add+1
> }
> 
> function main {
>      typeset -ix add=0
>      integer i=0
> 
>      while [[ $1 -lt 5 ]]
>      do
>           do_add
>           echo "$add"
>      done
> }
> 
> In ksh, the variable add is successfully updated across calls to do_add.
> i.e. add is 5 when main function completes.
> 
> Running a similar script on/bin/ksh or /bin/ksh93 on Opensolaris 111b
> does not work. 
> 
> /bin/ksh       : Version M 93t 2008-11-04
> /bin/ksh93     : Version M 93t 2008-11-04
> 
> Running in these shells tries to assign "add+1" to add instead of performing
> an arithmetic expression. Is this expected due to changes between ksh93
> and ksh88 (Version M-11/16/88i)
> 
> Thanks,
> 
> Jon
> -- 
> This message posted from opensolaris.org

David Korn
dgk at research.att.com

Reply via email to