Space as a key in an associative array - different behaviours
From:
Tomasz Warniełło
Subject:
Space as a key in an associative array - different behaviours
Date:
Thu, 25 Jan 2018 14:48:47 +0100
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H -I. -I../. -I.././include -I.././lib -Wdate-time
-D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/build/bash-7fckc0/bash-4.4=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall -no-pie
-Wno-parentheses -Wno-format-security
uname output: Linux tomas 4.9.0-5-amd64 #1 SMP Debian 4.9.65-3+deb9u2
(2018-01-04) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 4.4
Patch Level: 12
Release Status: release
Description:
When trying to assign to a space key of an associative array,
the result differs with regards to the way the operation is performed.
1. ((A[$a]++))
2. let "A[' ']++"
3. A[" "]=1
I've asked a question about this here:
https://unix.stackexchange.com/questions/419488/bash-space-as-a-key-in-an-assoc$
Repeat-By:
1.
$ unset A; a=" ";declare -A A; ((A[$a]++)); declare -p A
declare -A A
2.
$ unset A; a=" ";declare -A A; let "A[$a]=1"; declare -p A
declare -A A
3.
$ unset A; a=" ";declare -A A; A[$a]=1; declare -p A
declare -A A=([" "]="1" )