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

Path csiph.com!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!171.64.64.130.MISMATCH!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: [BUG] 'unset' fails silently under specific conditions
Date Wed, 2 May 2018 10:32:52 -0400
Lines 66
Approved bug-bash@gnu.org
Message-ID <mailman.13278.1525271610.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> <d87ee315-f35d-67e5-32a7-44d40110b5fd@inlv.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1525271611 8282 208.118.235.17 (2 May 2018 14:33:31 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
Mail-Followup-To bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <d87ee315-f35d-67e5-32a7-44d40110b5fd@inlv.org>
User-Agent NeoMutt/20170113 (1.7.2)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
X-Received-From 139.137.100.1
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:14080

Show key headers only | 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