Received: by mail.netbsd.org (Postfix, from userid 605) id 08DA984DA8; Sat, 27 May 2017 06:32:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id 8A6ED84D9C for ; Sat, 27 May 2017 06:32:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([127.0.0.1]) by localhost (mail.netbsd.org [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id 2HfKR_ZThkpp for ; Sat, 27 May 2017 06:32:13 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.netbsd.org [199.233.217.197]) by mail.netbsd.org (Postfix) with ESMTP id DF91384D7B for ; Sat, 27 May 2017 06:32:12 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id D9441FBE4; Sat, 27 May 2017 06:32:12 +0000 (UTC) Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" MIME-Version: 1.0 Date: Sat, 27 May 2017 06:32:12 +0000 From: "Robert Elz" Subject: CVS commit: src/bin/sh To: source-changes@NetBSD.org X-Mailer: log_accum Message-Id: <20170527063212.D9441FBE4@cvs.NetBSD.org> Sender: source-changes-owner@NetBSD.org List-Id: source-changes.NetBSD.org Precedence: bulk Reply-To: source-changes-d@NetBSD.org Mail-Reply-To: "Robert Elz" Mail-Followup-To: source-changes-d@NetBSD.org List-Unsubscribe: Module Name: src Committed By: kre Date: Sat May 27 06:32:12 UTC 2017 Modified Files: src/bin/sh: sh.1 var.c Log Message: It turns out that most shells do not do variable value/attribute inheritance when a variable is declared local, but instead leave the local var unset (if not given a value) in the function. Only ash derived shells do inheritance it seems. So, to compensate for that, and get one step closer to making "local" part of POSIX, so we can really rely upon it, a compromise has been suggested, where "local x" is implementation defined when it comes to this issue, and we add "local -I x" to specify inheritance, and "local -N x" to specify "not" (something...) (not inherited, or not set, or whatever you prefer to imagine!) The option names took a lot of hunting to find something reasonable that no shell (we know of) had already used for some other purpose... The I was easy, but 'u' 'U' 'X' ... all in use somewhere. This implements that (well, semi-) agreement. While here, add "local -x" (which many other shells already have) which causes the local variable to be made exported. Not a lot of gain in that (since "export x" can always be done immediately after "local x") but it is very cheap to add and allows more other scripts to work with out shell. Note that while 'local x="${x}"' always works to specify inheritance (while making the shell work harder), "local x; unset x" does not always work to specify the alternative, as some shells have "re-interpreted" unset of a local variable to mean something that would best be described as "unlocal" instead - ie: after the unset you might be back with the variable from the outer scope, rather than with an unset local variable. Also add "unset -x" to allow unsetting a variable without removing any exported status it has. There are gazillions of other options that are not supported here! To generate a diff of this commit: cvs rdiff -u -r1.143 -r1.144 src/bin/sh/sh.1 cvs rdiff -u -r1.53 -r1.54 src/bin/sh/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.