Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Martijn Dekker Newsgroups: gnu.bash.bug Subject: Re: [BUG] persistently assigned variable cannot be unexported in POSIX mode Date: Mon, 30 Apr 2018 20:57:08 +0200 Lines: 47 Approved: bug-bash@gnu.org Message-ID: References: <2965f169-3d43-abf9-73a9-bc3142e2ef95@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1525114650 12813 208.118.235.17 (30 Apr 2018 18:57:30 GMT) X-Complaints-To: action@cs.stanford.edu To: chet.ramey@case.edu, "bug-bash@gnu.org" Envelope-to: bug-bash@gnu.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 In-Reply-To: <2965f169-3d43-abf9-73a9-bc3142e2ef95@case.edu> Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 37.59.109.123 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14064 Op 27-04-18 om 22:16 schreef Chet Ramey: > On 4/25/18 10:51 PM, Martijn Dekker wrote: > >> What I'm reporting here is a bug I discovered with unexporting a variable >> that is so exported while bash is in POSIX mode. It cannot be unexported >> using 'typeset +x' if you try to do that in a shell function. >> >> This works: >> >> $ bash -o posix -c 'foo=abc : ; typeset +x foo; env|grep ^foo=' >> (no output, as expected: no longer exported) >> >> But this doesn't: >> >> $ bash -o posix -c 'fn() { foo=abc : ; typeset +x foo; env|grep ^foo=; }; fn' >> foo=abc > > It seems like you're assuming that in posix mode, variable assignments that > precede special builtins executed in shell functions should create local > variables. Is that correct? No. The issue is: 1. In POSIX mode, as ':' is a so-called special builtin, "foo=abc :" causes the assignment to 'foo' to persist past the ':' command, and 'foo' also remains exported. This is all POSIX-compliant. (I really wish it didn't remain exported, though. POSIX allows it, but doesn't mandate it; it's unspecified whether it remains exported or not. But it seems broken for it to remain exported. In fact I'm not sure why it's exported to begin with. As far as I know, there are no special builtins that run external binaries.) 2. The bug is: 'declare +x' a.k.a. 'typeset +x' then fails to unexport the variable in the second version above. The variable remains exported past 'typeset +x foo', as proven by grepping the output of 'env'. It shouldn't matter if the variable is local to the function or not, as everything is done in the same scope. 'declare +x' should clear the export flag as it is documented to do. In the second invocation quoted above, it doesn't. Having said that, I now cannot reproduce the issue in the 2018-04-27 development snapshot... so thanks for fixing it anyhow :) - Martijn