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


Groups > gnu.bash.bug > #14080

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

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: [BUG] 'unset' fails silently under specific conditions
Date 2018-05-02 10:32 -0400
Message-ID <mailman.13278.1525271610.27995.bug-bash@gnu.org> (permalink)
References (2 earlier) <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> <d87ee315-f35d-67e5-32a7-44d40110b5fd@inlv.org>

Show all headers | View raw


On Wed, May 02, 2018 at 03:07:42PM +0100, Martijn Dekker wrote:
> 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'.

Here's what I get:

wooledg:~$ bash
wooledg:~$ set -o posix
wooledg:~$ f() { foo=bar : ; }; f
wooledg:~$ declare -p foo
declare -x foo="bar"
wooledg:~$ declare +x foo
wooledg:~$ declare -p foo
declare -- foo="bar"

So, 1 and 2 are correct, but it's not "permanently" exported.  The
export flag is removable.

> 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.

That isn't what I see.

wooledg:~$ bash
wooledg:~$ set -o posix
wooledg:~$ f() { foo=bar; foo=baz : ; }; f
wooledg:~$ declare -p foo
declare -x foo="baz"

What did you see that led you to conclude there is a local variable
involved?  (Not counting discussions with Chet!)

wooledg:~$ bash
wooledg:~$ set -o posix
wooledg:~$ f() { foo=bar; declare -p foo; foo=baz :; declare -p foo; }; f
declare -- foo="bar"
declare -x foo="baz"
wooledg:~$ declare -p foo
declare -x foo="baz"

All the evidence I'm seeing points to just plain global variables in
this example.

wooledg:~$ bash
wooledg:~$ set -o posix
wooledg:~$ f() { foo=bar :; declare +x foo; declare -p foo; }; f
declare -- foo="bar"
wooledg:~$ declare -p foo
declare -x foo="bar"

Same here.  Global variable, survives the function, no longer exported.

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


Thread

Re: [BUG] 'unset' fails silently under specific conditions Greg Wooledge <wooledg@eeg.ccf.org> - 2018-05-02 10:32 -0400

csiph-web