From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25349 invoked by alias); 29 Apr 2015 15:39:46 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34999 Received: (qmail 23448 invoked from network); 29 Apr 2015 15:39:28 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS autolearn=ham version=3.3.2 Message-ID: <5540F9B6.5020805@case.edu> Date: Wed, 29 Apr 2015 11:33:10 -0400 From: Chet Ramey Reply-To: chet.ramey@case.edu User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Peter Stephenson , zsh-workers@zsh.org CC: chet.ramey@case.edu Subject: Re: [BUG] Can't mark unset variables as read-only References: <55407BBF.6020401@inlv.org> <20150429113602.374240c7@pwslap01u.europe.root.pri> <150429065556.ZM31553@torch.brasslantern.com> <20150429154136.152b7b05@pwslap01u.europe.root.pri> In-Reply-To: <20150429154136.152b7b05@pwslap01u.europe.root.pri> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Junkmail-Status: score=10/50, host=mpv6.cwru.edu X-Junkmail-Whitelist: YES (by domain whitelist at mpv2.tis.cwru.edu) On 4/29/15 10:41 AM, Peter Stephenson wrote: > On Wed, 29 Apr 2015 06:55:56 -0700 > Bart Schaefer wrote: > >> On Apr 29, 11:36am, Peter Stephenson wrote: >> } >> } +Note that in zsh (unlike other shells) it is still possible >> } +to create a local variable of the same name as this is considered a >> } +different variable (though this variable, too, can be marked readonly). >> >> Hrm, I wonder if that, combined with "typeset" automatically creating >> locals when called in a function context (also a POSIX incompatibility?) It's not a Posix incompatibility; Posix does not specify typeset or local variables at all. The Posix-conformant ways of declaring variables in a function result in global variables, as Posix specifies. >> defeats the whole purpose of an unset readonly? The question is whether or not you can use local variables to `shadow' readonly variables in a previous scope. Bash doesn't allow you to do that. Given this script: readonly foo=immutable func() { local foo=bar echo inside: $foo } func echo outside: $foo Bash gives the following output: ./x26: line 5: local: foo: readonly variable inside: immutable outside: immutable If the purpose of readonly is to make a particular name/value pair immutable, I think that allowing a local variable to shadow it, especially if you're going to export that local variable, is a bad thing. > > I don't think so... bash makes these local, too: > > $ foo=bar > $ fn() { typeset foo=something_else; echo $foo; } > $ fn > something_else > $ echo $foo > bar > > So "foo" in fn is logically something entirely different and I don't > think there's any requirement for it to be treated as readonly; There's no requirement, since there are no standards for local variables or variable scoping. Bash does what I think is right. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/