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


Groups > gnu.bash.bug > #13775 > unrolled thread

Re: Unset array doesn't work

Started byGreg Wooledge <wooledg@eeg.ccf.org>
First post2018-02-28 15:00 -0500
Last post2018-02-28 15:00 -0500
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Unset array doesn't work Greg Wooledge <wooledg@eeg.ccf.org> - 2018-02-28 15:00 -0500

#13775 — Re: Unset array doesn't work

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2018-02-28 15:00 -0500
SubjectRe: Unset array doesn't work
Message-ID<mailman.9902.1519848059.27995.bug-bash@gnu.org>
I think most people will agree that unset is extremely surprising,
though they may point to different parts of it as the source of their
surprise.

8 years after Freddy Vulto's initial investigations, there are many
things I still don't understand.  For example, consider this code
straight from his web site[1]:

=====================================================================
wooledg:~$ cat freddy
#!/bin/bash

a=0 b=0 c=0 d=0 e=0
_unset() { unset -v b c c d d d e; }
t1() {
    local a=1 b=1 c=1 d=1
    t2
}
t2() {
    local a=2 b=2 c=2 d=2 e=2
    _unset
    echo a:$a b:$b c:$c d:$d e:$e
}
t1
wooledg:~$ ./freddy
a:2 b:1 c:0 d: e:0
=====================================================================

But if I make a tiny change to it (eliminating the _unset function which
*appears* to have no purpose), it has entirely different behavior:

=====================================================================
wooledg:~$ cat freddy2
#!/bin/bash

a=0 b=0 c=0 d=0 e=0
t1() {
    local a=1 b=1 c=1 d=1
    t2
}
t2() {
    local a=2 b=2 c=2 d=2 e=2
    unset -v b c c d d d e
    echo a:$a b:$b c:$c d:$d e:$e
}
t1
wooledg:~$ ./freddy2
a:2 b: c: d: e:
=====================================================================

I don't understand the difference.

Does unset create some kind of "placeholder" in the current function
(but not in a caller)?

[1] http://fvue.nl/wiki/Bash:_Unset

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web