Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14079

Re: [BUG] 'unset' fails silently under specific conditions

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Martijn Dekker <martijn@inlv.org>
Newsgroups gnu.bash.bug
Subject Re: [BUG] 'unset' fails silently under specific conditions
Date Wed, 2 May 2018 15:07:42 +0100
Lines 46
Approved bug-bash@gnu.org
Message-ID <mailman.13275.1525270079.27995.bug-bash@gnu.org> (permalink)
References <a16a34cf-eea7-16b8-76d8-e05d0fe2cc32@inlv.org> <1295e1ea-73c0-e479-da03-b784ec975030@inlv.org> <59161dc5-bb33-d842-4af3-477e8784a4f5@inlv.org> <71d753dc-036f-7fd7-d703-408c3f8ac202@case.edu> <48f7a2c2-70ce-0994-33e0-6b2282a3b5f6@inlv.org> <aa36f1ca-ca58-ebee-4f95-2e76e5221721@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 1525270079 7353 208.118.235.17 (2 May 2018 14:07:59 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 <aa36f1ca-ca58-ebee-4f95-2e76e5221721@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 <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://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>
Xref csiph.com gnu.bash.bug:14079

Show key headers only | View raw


Op 02-05-18 om 02:20 schreef Chet Ramey:
> You complained that `typeset +x' didn't `unexport' a variable.  The reason > is that the variable assignment preceding the special builtin caused a
> variable to be created at the global scope, and the `typeset' resulted in
> a local variable being created.

I still can't see how that is relevant here: 'typeset'/'declare' is not 
involved in the current issue. But then, neither is 'unset'. It does 
appear that the current issue is not what I thought it was.

Instead, in POSIX mode, it looks like a variable assignment preceding a 
special builtin may create a variable at a function-local scope without 
'typeset'/'declare' being involved at all. But not always.

Let's see if I'm getting it right this time. In the following:
	set -o posix
	f() { foo=bar : ; }
	f
the command 'foo=bar :'
1. makes the assignment 'foo=bar' survive the ':' command;
2. gives 'foo' a global scope;
3. permanently exports the global variable 'foo'.

However, in the following:
	set -o posix
	f() { foo=bar; foo=baz : ; }
	f
the plain assignment 'foo=bar' creates an ordinary global variable named 
'foo' with value 'bar', and then the command 'foo=bar :'
1. makes the assignment 'foo=baz' survive the ':' command, but by 
creating *another* 'foo' instead of overwriting the first;
2. gives that other 'foo' a function-local scope;
3. exports the local variable 'foo' for the duration of its existence.

My testing confirms that this is what appears to happen, and I think 
it's a bug, because (1) POSIX has no notion of variables with a 
function-local scope; (2) even if it did, no command was issued that 
should make the variable local to the function; and (3) the behaviour in 
the second example is inconsistent with that in the first.

I think 'foo=baz :' should act the same in the second example as 
'foo=bar :' does in the first, i.e.: if there is already a variable by 
that name it should be overwritten, just like with any normal shell 
assignment.

- M.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: [BUG] 'unset' fails silently under specific conditions Martijn Dekker <martijn@inlv.org> - 2018-05-02 15:07 +0100

csiph-web