Description of problem: the customer is using RHEL 5.1 and ksh-20060214-1.4, they bring the following behaviour to our attention as a bug, this is reproducible 100% with RHEL 5.1 and ksh-20060214-1.4 (so I don't attach (sys|sos)reports for the moment). Version-Release number of selected component (if applicable): ksh-20060214-1.4 How reproducible: always Steps to Reproduce: 1.If you run the following script (in attach as "typeset.ksh"): #!/bin/ksh function f { let N=N-1 || return print ${X}${Y} typeset -x X=B Y=b f } typeset -i10 N=3 typeset -x X=A typeset -x Y=a f you get the following output: Aa Ab But the output the customer expects (and that, as far as I can see from the commands in ksh) should be: Aa Bb I'm not an expert of ksh, but from my understanding the behaviour of this script is similar to the bash script that I've created and attached ("typeset.sh"): #!/bin/bash f () { N=$(($N-1)) [ $N -eq 0 ] && return echo ${X}${Y} export X=B Y=b f } N=3 export X=A export Y=a f If you change (in the ksh script) the line: typeset -x X=B with X=B the issue disappears. So probably the issue is connected to the behaviour of "typeset -x" in (recursive?) subfunctions. The customer has a workaround, so this is not an important issue for them at the moment. Additional info:
I have a similar problem at a client where the following example: #!/bin/ksh sub_func() { typeset ATTRIBUT=6 echo "The function set a private variable to : $ATTRIBUT" } typeset ATTRIBUT=1 echo "The following should have the same value before and after a function call:" echo "Before function call: $ATTRIBUT" sub_func echo "After function call: $ATTRIBUT" The previous code returns: The following should have the same value before and after a function call: Before function call: 1 The function set a private variable to : 6 After function call: 6 While it returns the following on AIX, HP-UX, OSF1, and Solaris: The following should have the same value before and after a function call: Before function call: 1 The function set a private variable to : 6 After function call: 1
I don't think any of these are bugs. The ksh manual page says that functions defined with 'function name' syntax share the variables with the calling program with an exception of variables defined with 'typeset' command that are defined as local in the scope of the function. Using '-x' has no effect since the function would have its own environment. The X variable defined with typeset inside the function overshadows the variable X from callers environment but only in the scope of the function. The next (recursive) call will start with variable X taken from the original environment since it is a different scope already. Things are different with functions defined with 'name()' syntax. Those functions run completely in the caller's environment (no exception for typeset). This also explains the "issue" in comment #1 -- try to define the function as 'function sub_func'... This is a documented and expected behaviour. I think the biggest problem here is that the behaviour was different in ksh88 (RHEL-5 comes with ksh93) that is present on AIX, HP-UX, old Solaris (I think the new OpenSolaris is already shipped with ksh93 as well), etc. which causes the confusion.
This request was evaluated by Red Hat Product Management for inclusion in a Red Hat Enterprise Linux maintenance release. Product Management has requested further review of this request by Red Hat Engineering, for potential inclusion in a Red Hat Enterprise Linux Update release for currently deployed products. This request is not yet committed for inclusion in an Update release.
Development Management has reviewed and declined this request. You may appeal this decision by reopening this request.