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-24 20:10 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... ======================================================================
---------------------------------------------------------------------- (0003748) chet_ramey (reporter) - 2017-05-24 20:10 http://austingroupbugs.net/view.php?id=767#c3748 ---------------------------------------------------------------------- Re: http://austingroupbugs.net/view.php?id=767#c3747 > That's why I support the view that `local x' > by itself does not set a variable x: > > Of course not, is there anyone claimimg differently? I guess it depends on what people mean by things like a "pushed instance" or "local variant". It creates a new object, that much seems clear. But does that new object have a value? > > because it hasn't been assigned a value. > > but here you are venturing into the unknown. How do you know that? Because, unless it has already been declared at the same local scope, it creates a new object. That's the essential question. > > In the sequence > > X=foo > local X > > X has clearly been assigned a value, you can see it right there. OK. How many `instances' of X should now exist, and what are their values? Should there be an `X' at the global scope, and a separate instance of X at the local scope? We all agree that subsequent assignments to X should not affect the copy at the global scope, which should remain with value "foo". If you treat them as different objects, then the local instance of X is unset because it hasn't been assigned a value. This is the crux of the value inheritance question. > > Of course if your "because it hasn't been assigned" was reworded > as "because it is not being assigned" then I'd agree. > > You only get a different opinion if you believe that "local" is creating > something new, rather than arrannging to save, and later restore, the > value of X. I prefer local to be just like the existing export, and > readonly, they set attributes on a variable, they do not create them. Yes. That's the question. > > This model also does away with scoping questions completely. There > only is one scope (just as now in POSIX) - "local" is just doing the > equivalent of > save_X="${X}" # possibly followed by: unset X > > and arranging for "return" (including the implicit one at func end, > and any exit of the func caused by an abort that does not cause the > shell to exit) to do > > X="${save_X}" > > but also including attributes, and using anonymous save variables. Not really. You're just implicitly resolving the question in favor of dynamic scoping. If function A runs `local X', runs X=4, and calls function B, does B see a set variable X, and, if so, what is its value? If you say `yes' and `4', you've chosen dynamic scoping. > I think you'd agree that if in > > X=foo > export X > > X was now unset, no-one would be happy. Nobody would expect X to be unset after running that. It's irrelevant. It's the same question as if I were to run `export X', where X was not previously set: would I expect X to suddenly have a value? > Why should there be a difference > for local? Because local has `shadowing' effects on any variable with the same name in a previous scope. It's those effects we're talking about. We have differing views. 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 2017-05-23 13:08 joerg Note Added: 0003708 2017-05-23 13:18 joerg Note Added: 0003709 2017-05-23 13:19 joerg Note Edited: 0003709 2017-05-23 13:41 chet_ramey Note Added: 0003710 2017-05-23 13:47 joerg Note Added: 0003711 2017-05-23 13:47 chet_ramey Note Added: 0003712 2017-05-23 13:51 joerg Note Added: 0003713 2017-05-23 14:00 chet_ramey Note Added: 0003714 2017-05-23 14:05 chet_ramey Note Added: 0003715 2017-05-23 14:11 stephane Note Added: 0003716 2017-05-23 14:14 chet_ramey Note Added: 0003717 2017-05-23 14:17 joerg Note Added: 0003718 2017-05-23 14:19 stephane Note Added: 0003719 2017-05-23 14:26 chet_ramey Note Added: 0003720 2017-05-23 14:29 chet_ramey Note Added: 0003721 2017-05-23 14:32 chet_ramey Note Added: 0003722 2017-05-23 14:45 joerg Note Added: 0003723 2017-05-23 15:16 chet_ramey Note Added: 0003724 2017-05-23 15:29 stephane Note Added: 0003725 2017-05-23 16:34 shware_systems Note Added: 0003726 2017-05-23 17:28 shware_systems Note Added: 0003727 2017-05-23 17:43 chet_ramey Note Added: 0003728 2017-05-23 18:49 shware_systems Note Added: 0003729 2017-05-23 22:54 kre Note Added: 0003730 2017-05-23 23:38 kre Note Added: 0003731 2017-05-23 23:48 kre Note Edited: 0003731 2017-05-23 23:57 kre Note Edited: 0003731 2017-05-24 00:06 kre Note Added: 0003732 2017-05-24 00:18 kre Note Edited: 0003732 2017-05-24 00:40 kre Note Edited: 0003732 2017-05-24 07:31 shware_systems Note Added: 0003733 2017-05-24 09:25 stephane Note Added: 0003735 2017-05-24 09:53 kre Note Added: 0003736 2017-05-24 10:37 kre Note Added: 0003737 2017-05-24 10:38 kre Note Edited: 0003737 2017-05-24 10:56 joerg Note Added: 0003738 2017-05-24 11:24 stephane Note Added: 0003739 2017-05-24 11:26 stephane Note Edited: 0003739 2017-05-24 11:30 stephane Note Edited: 0003739 2017-05-24 12:08 kre Note Added: 0003740 2017-05-24 12:23 kre Note Added: 0003741 2017-05-24 12:27 kre Note Added: 0003742 2017-05-24 12:42 stephane Note Added: 0003743 2017-05-24 12:59 kre Note Added: 0003744 2017-05-24 13:02 joerg Note Added: 0003745 2017-05-24 13:09 joerg Note Edited: 0003745 2017-05-24 13:20 joerg Note Edited: 0003745 2017-05-24 13:26 chet_ramey Note Added: 0003746 2017-05-24 13:41 joerg Note Edited: 0003745 2017-05-24 16:20 kre Note Added: 0003747 2017-05-24 20:10 chet_ramey Note Added: 0003748 ======================================================================