[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Unset array doesn't work
From: |
Nikolai Kondrashov |
Subject: |
Re: Unset array doesn't work |
Date: |
Mon, 12 Feb 2018 08:41:34 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
Hi Chet,
On 02/12/2018 01:31 AM, Chet Ramey wrote:
On 2/11/18 1:06 PM, Nikolai Kondrashov wrote:
Hi everyone,
I think I'm hitting a bug in Bash 4.4.12 (on Debian Stable): at some point
an "unset" of a global array variable doesn't work inside a function, in
"dkms" script from DKMS package. Adding another "unset" of the same variable
next to it fixes the issue.
Do you have a local variable with the same name "shadowing" the global?
Thank you for the quick response!
Looking more into this, the variable in question is defined as a local in the
calling function and is being "unset" in a function called from that one.
I think this is what's happening and seems to reproduce the issue:
#!/bin/bash
inner() {
unset res
if [[ $1 == "set" ]]; then
res[0]="X"
res[1]="Y"
fi
}
outer() {
local res=
inner "$1"
echo "res: ${res[@]}"
}
outer set
outer dontset
The produced output is this:
res: X Y
res: X Y
The expected output is this:
res: X Y
res:
Sorry, if this is not minimal enough. Had little time to whittle it down.
This seems to me rather a gray area, and I wouldn't be too surprised if this
was by design, but it does feel wrong.
Thank you.
Nick
- Unset array doesn't work, Nikolai Kondrashov, 2018/02/11
- Re: Unset array doesn't work, Chet Ramey, 2018/02/11
- Re: Unset array doesn't work,
Nikolai Kondrashov <=
- Re: Unset array doesn't work, Nikolai Kondrashov, 2018/02/12
- Re: Unset array doesn't work, Clark Wang, 2018/02/12
- Re: Unset array doesn't work, Nikolai Kondrashov, 2018/02/12
- Re: Unset array doesn't work, Clark Wang, 2018/02/12
- Re: Unset array doesn't work, Nikolai Kondrashov, 2018/02/12
- Re: Unset array doesn't work, Chet Ramey, 2018/02/12
- Re: Unset array doesn't work, Nikolai Kondrashov, 2018/02/12
- Re: Unset array doesn't work, Robert Elz, 2018/02/26
- Re: Unset array doesn't work, Clint Hepner, 2018/02/26
- Re: Unset array doesn't work, Greg Wooledge, 2018/02/26