Bug 151133

Summary: ksh does not pass local variables to subfunctions
Product: Red Hat Enterprise Linux 4 Reporter: ilja lunev <uxadm>
Component: kshAssignee: Karsten Hopp <karsten>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 4.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-03-16 12:00:53 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description ilja lunev 2005-03-15 10:47:57 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.1)
Gecko/20040707

Description of problem:
local variables are not passed to subordinated functions
(see example below)
In posix shell, pdksh and on HPUX ksh the output of the sample script is
string1
string2
whereas ksh-20040229 outputs
string1
string1

EXAMPLE
===============
function A
{ print $Var
}
function B
{ Var=string1
  A
  typeset Var
  Var=string2
  A
}
# MAIN
B                  # invoke test function



Version-Release number of selected component (if applicable):
ksh-20040229-12.i386.rpm

How reproducible:
Always

Steps to Reproduce:
1. Run scriptlet in ksh
2.
3.
    

Actual Results:
string1
string1

Expected Results:
string1
string2

Additional info:
Of course I can work around this by passing the parameter(s) to the
function which would be good style anyway.
But because other ksh versions behave differently every legacy script
has to be reviewed to make sure all results are correct.

Comment 1 Karsten Hopp 2005-03-16 12:00:53 UTC
HPUX is probably using ksh88 where the scoping of variables was undefined.
ksh93 has static scoping specified and this is the expected behaviour.
Please have a look at the official KornShell FAQ, Question 28 at
http://www.kornshell.com/doc/faq.html