Bug 431448
Summary: | CRM# 1792308 - ksh variable scope when typeset -x | ||
---|---|---|---|
Product: | Red Hat Enterprise Linux 5 | Reporter: | Alan Matsuoka <alanm> |
Component: | ksh | Assignee: | Tomas Smetana <tsmetana> |
Status: | CLOSED WONTFIX | QA Contact: | |
Severity: | low | Docs Contact: | |
Priority: | low | ||
Version: | 5.1 | CC: | serge.bonin, tao |
Target Milestone: | rc | ||
Target Release: | --- | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Fixed In Version: | Doc Type: | Bug Fix | |
Doc Text: | Story Points: | --- | |
Clone Of: | Environment: | ||
Last Closed: | 2008-06-16 12:46:40 UTC | Type: | --- |
Regression: | --- | Mount Type: | --- |
Documentation: | --- | CRM: | |
Verified Versions: | Category: | --- | |
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
Cloudforms Team: | --- | Target Upstream Version: | |
Embargoed: | |||
Bug Depends On: | |||
Bug Blocks: | 391501 |
Description
Alan Matsuoka
2008-02-04 16:09:39 UTC
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. |