[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [BUG] 'unset' fails silently under specific conditions
From: |
Greg Wooledge |
Subject: |
Re: [BUG] 'unset' fails silently under specific conditions |
Date: |
Wed, 2 May 2018 10:32:52 -0400 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
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.
- [BUG] 'unset' fails silently under specific conditions, Martijn Dekker, 2018/05/01
- Re: [BUG] 'unset' fails silently under specific conditions, Martijn Dekker, 2018/05/01
- Re: [BUG] 'unset' fails silently under specific conditions, Chet Ramey, 2018/05/01
- Re: [BUG] 'unset' fails silently under specific conditions, Martijn Dekker, 2018/05/01
- Re: [BUG] 'unset' fails silently under specific conditions, Chet Ramey, 2018/05/01
- Re: [BUG] 'unset' fails silently under specific conditions, Martijn Dekker, 2018/05/02
- Re: [BUG] 'unset' fails silently under specific conditions,
Greg Wooledge <=
- Re: [BUG] 'unset' fails silently under specific conditions, Greg Wooledge, 2018/05/02
- Re: [BUG] 'unset' fails silently under specific conditions, Martijn Dekker, 2018/05/02
- Re: [BUG] 'unset' fails silently under specific conditions, Chet Ramey, 2018/05/02
Re: [BUG] 'unset' fails silently under specific conditions, Robert Elz, 2018/05/01