Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16260
| Path | csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | worley@alum.mit.edu (Dale R. Worley) |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Local variable names clash with global read-only variable names. |
| Date | Thu, 30 Apr 2020 22:43:53 -0400 |
| Lines | 25 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1733.1588301045.3066.bug-bash@gnu.org> (permalink) |
| References | <be8dd110-c269-be88-b14c-8359e4c547f5@case.edu> <87wo5wgys6.fsf@hobgoblin.ariadne.com> |
| NNTP-Posting-Host | lists.gnu.org |
| X-Trace | usenet.stanford.edu 1588301046 29834 209.51.188.17 (1 May 2020 02:44:06 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | andrej@podzimek.org, bug-bash@gnu.org, chet.ramey@case.edu |
| To | chet.ramey@case.edu |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20180828_2048; t=1588301038; bh=GbrxdsX/noronqJSHhneGZWTXa4RPRkICiAvS4iH6oo=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID; b=hAn3xpv/zoGPVa/2g7t413Ag12VhFcv8YbZfHk74B0PcdXWNs4Lwh0Jp7EfQOJ1sX GSCFrNPGazjK4K8IlQBx1VmMfxM7eiP1NRJgG4QRe81gyJttdsnPdJNSQtVu1Ta6cA pd355tcak9d9Whm+9DRqRzk3IU0TStrcgJ1TtwyIvL5clAtBjR7TnQUkMQW4wB7kU/ MYtaJwU/GUg6ANls7AUp6lKkBXhalj6rzuE+/zb2SyFDChAwS0d3dMskYCqXaG0i/t DT4yCOEe7ctIzG0+VklQpXuDNJPu35FPRUdAJVkIHiPRAIPVzD1Qoxcu/TR4urY2yX 2ozaTQGVIthTQ== |
| X-Xfinity-VMeta | sc=0.00;st=legit |
| X-Authentication-Warning | hobgoblin.ariadne.com: worley set sender to worley@alum.mit.edu using -f |
| In-Reply-To | <be8dd110-c269-be88-b14c-8359e4c547f5@case.edu> (chet.ramey@case.edu) |
| Received-SPF | permerror client-ip=2001:558:fe21:29:69:252:207:34; envelope-from=worley@alum.mit.edu; helo=resqmta-ch2-02v.sys.comcast.net |
| X-detected-operating-system | by eggs.gnu.org: First seen = 2020/04/30 22:43:58 |
| X-ACL-Warn | Detected OS = ??? |
| X-Received-From | 2001:558:fe21:29:69:252:207:34 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <87wo5wgys6.fsf@hobgoblin.ariadne.com> |
| Xref | csiph.com gnu.bash.bug:16260 |
Show key headers only | View raw
>>> f() { local x=a; }
>>> declare -r x
>>> f # bash: local: x: readonly variable
>>>
>>> This^^^ should not fail; it hinders reusability of shell functions and makes
>>> them context-dependent.
It's "natural" to think that a variable that is local to a function
should be independent of however it is declared globally. The problem
is that bash local variables aren't lexically scoped -- when you enter
the function, the variable acquires the new value, but any function that
is called by this function sees the new value, even if that function
wasn't declared inside the function that declared the variable local.
So if a local declaration could override a readonly declaration, the new
value could be seen by code unrelated the function that did the
override.
This is a common issue in language design. The Perl language originally
only had "local" declarations that behaved the same way as bash local
declarations. But the above behavior got to be so much of a problem for
large programs that Perl added a separate lexically-scoped local
declaration.
Dale
Back to gnu.bash.bug | Previous | Next | Find similar
Re: Local variable names clash with global read-only variable names. worley@alum.mit.edu (Dale R. Worley) - 2020-04-30 22:43 -0400
csiph-web