robin217
(Robin A. Meade)
1
I’m puzzled why the following line gives different results between Fedora 34 and Fedora 35.
declare -A array=([a]=""); [[ -v array[@] ]] && echo yes || echo no
On my Fedora 34 laptop, the result is no
.
On Fedora 35 running in a VM, the result is yes
.
On both machines, the version of bash is 5.1.8
.
According to https://unix.stackexchange.com/a/321654, the expected result is yes
.
Why would the behavior be different?
Also, can somebody confirm that they get no
on Fedora 34?
1 Like
oprizal
(Syaifur Rizal)
2
Weird. I test on F34 virtual machine, all give me yes
. I can get no
if I’m using |
instead of ||
.
2 Likes
alciregi
(Alessio)
3
Same here. Tested on a Fedora Linux 34 virtual machine as well on 35, and I get yes
.
2 Likes
vgaetera
(Vladislav Grigoryev)
4
This happens when your default shell is not Bash, but Zsh:
> CMD='declare -A array=([a]=""); [[ -v array[@] ]] && echo yes || echo no'
> bash -c "${CMD}"
yes
> zsh -c "${CMD}"
no
3 Likes
robin217
(Robin A. Meade)
5
Thanks everyone.
It turns out I had tested a bash update back in July and forgot about it.
bash-5.1$ sudo dnf history bash
[sudo] password for robin:
ID | Command line | Date and time | Action(s) | Altered
------------------------------------------------------------------------------------------------------------------------
64 | install --nogpgcheck ./bash-5.1.9.0-2.fc34.x86_64.rpm 0xFFFF-0.9- | 2021-07-11 22:06 | I, U | 2
63 | install --nogpgcheck ./bash-5.1.8.0-2.fc34.x86_64.rpm | 2021-07-11 13:59 | Upgrade | 1 <
1 | | 2021-04-23 00:56 | Install | 1709 >E
I reinstalled bash to be the proper version distributed with Fedora 34 (5.1.0
). I now get the expected yes
.
2 Likes