A NOTE has been added to this issue. ====================================================================== http://austingroupbugs.net/view.php?id=767 ====================================================================== Reported By: dwheeler Assigned To: ajosey ====================================================================== Project: 1003.1(2008)/Issue 7 Issue ID: 767 Category: Shell and Utilities Type: Enhancement Request Severity: Objection Priority: normal Status: Under Review Name: David A. Wheeler Organization: User Reference: Section: XCU 2.14 (local) Page Number: 2374 Line Number: 75650 Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2013-10-11 02:02 UTC Last Modified: 2017-05-23 12:06 UTC ====================================================================== Summary: Add built-in "local" ====================================================================== Relationships ID Summary ---------------------------------------------------------------------- related to 0000771 Expose alternate shell function usage t... related to 0000465 is the list of special built-ins exhaus... related to 0001025 set description contains counterproduct... ======================================================================
---------------------------------------------------------------------- (0003707) stephane (reporter) - 2017-05-23 12:06 http://austingroupbugs.net/view.php?id=767#c3707 ---------------------------------------------------------------------- Re: http://austingroupbugs.net/view.php?id=767#c3704 [...] > If you need to pass values from the global scope, that is > already handled by positional parameters to the function, as > in "local var=$1;". [...] In addition to what Robert said, I'd add that so far the consensus seems to be that "local" would implement dynamic scoping (arguably ksh93-style static scoping may be better, but all shells that have a "local" implement dynamic scoping, and dynamic scoping is consistent with the kind of scoping you get with subshells, and interacts better with the environment (export)), and we can consider adding static scoping using a different syntax (like zsh's "private") later if need be. In that context, a "global scope" makes little sense. local var="$var" would create a local $var that is copy of what was assigned to $var before, that is the $var of the function's caller's scope (which would not necessarily be the "global scope"). A global scope makes sense in ksh93 that implements static scoping. bash does have some implementation of a "global scope", where typeset works differently (doesn't reset the value for instance) and can be accessed in functions with "typeset -g", but that's not very useful and is cause of confusion in practice (like code that behaves differently when sourced from a function or from the top-level). mksh, yash and zsh also have a "typeset -g" but it's to be able to set the type without limiting the scope (which is generally what you want to use that for), so the variable stays in the same scope. In bash, you'd get the variable of the top-level scope, not the variable of the caller. In ksh93 (again with static scoping), you can use namerefs (typeset -n) to get access to a variable in the scope of the caller. In mksh/zsh, you can define a function that changes the type of a variable like: integer() typeset -gi "$1" f() { local var integer var ... } In ksh93: function integer { typeset -ni v="$1"; } # or integer() typeset -i "$1" function f { typeset var integer var ... } You can't do that with bash AFAIK (you can set the type of a local variable, you can set the type of variable in the global scope but you cannot set the type of variable in your caller's scope unless that's the global scope) All that to say that "global scope" makes little sense with dynamic scoping other than to give a name to the top-level scope. Issue History Date Modified Username Field Change ====================================================================== 2013-10-11 02:02 dwheeler New Issue 2013-10-11 02:02 dwheeler Status New => Under Review 2013-10-11 02:02 dwheeler Assigned To => ajosey 2013-10-11 02:02 dwheeler Name => David A. Wheeler 2013-10-11 02:02 dwheeler Section => XCU 2.14 (local) 2013-10-11 02:02 dwheeler Page Number => 2374 2013-10-11 02:02 dwheeler Line Number => 75650 2013-10-11 08:31 geoffclare Relationship added related to 0000465 2013-10-15 22:47 dwheeler Note Added: 0001912 2013-10-17 05:52 ranjit Note Added: 0001924 2013-10-20 05:00 shware_systems Note Added: 0001937 2013-11-14 16:08 geoffclare Relationship added related to 0000771 2015-04-23 23:12 emaste Issue Monitored: emaste 2016-07-05 09:35 joerg Note Added: 0003285 2016-12-01 16:51 eblake Relationship added related to 0001025 2017-05-19 21:39 mirabilos Note Added: 0003699 2017-05-19 22:12 stephane Note Added: 0003701 2017-05-22 11:19 joerg Note Added: 0003702 2017-05-22 11:20 joerg Note Edited: 0003702 2017-05-22 11:20 joerg Note Edited: 0003702 2017-05-22 11:21 joerg Note Edited: 0003702 2017-05-22 19:38 stephane Note Added: 0003703 2017-05-22 23:06 shware_systems Note Added: 0003704 2017-05-23 03:41 kre Note Added: 0003705 2017-05-23 10:47 shware_systems Note Added: 0003706 2017-05-23 11:07 shware_systems Note Edited: 0003706 2017-05-23 12:06 stephane Note Added: 0003707 ======================================================================