Bug 151133 - ksh does not pass local variables to subfunctions
ksh does not pass local variables to subfunctions
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: ksh (Show other bugs)
4.0
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Karsten Hopp
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-03-15 05:47 EST by ilja lunev
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-03-16 07:00:53 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description ilja lunev 2005-03-15 05:47:57 EST
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 07:00:53 EST
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

Note You need to log in before you can comment on or make changes to this bug.