bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug adding K,V pairs to existing hash with HASH+=([K]=V)


From: Linda Walsh
Subject: bug adding K,V pairs to existing hash with HASH+=([K]=V)
Date: Mon, 15 Feb 2016 09:35:50 -0800

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.2 
-L/home/abuild/rpmbuild/BUILD/bash-4.2/../readline-6.2
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-suse-linux-gnu' 
-DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -fmessage-length=0 
-grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -g  -D_GNU_SOURCE -DRECYCLES_PIDS 
-Wall -g -Wuninitialized -Wextra -Wno-unprototyped-calls -Wno-switch-enum 
-Wno-unused-variable -Wno-unused-parameter -ftree-loop-linear -pipe 
-DBNC382214=0 -DIMPORT_FUNCTIONS_DEF=0 -fprofile-use
uname output: Linux Ishtar 4.1.0-Isht-Van #2 SMP PREEMPT Tue Jun 23 07:52:09 
PDT 2015 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-suse-linux-gnu

Bash Version: 4.2
Patch Level: 53
Release Status: release

Description:
        [Detailed description of the problem, suggestion, or complaint.]

        When I create hash and later add keys using the form
"HASH+=([key]=VALUE)", if KEY already existed in the HASH, then
I get the += applied to the VALUE as well
(strings get appended, ints get added).

Whether '+=' or '=' is used in the VALUE assignment, the
effect is '+='.

  Can I suggest that, maybe, this "interesting" behavior be
limited to the in-parens, "[KEY][+]=VAL" part?

Repeat-By:
(Example)

> alias sv='my -p'                          #(show_var)
> hash cfg=(); sv cfg
declare -A cfg='()'                         #empty hash

> cfg+=([one]=1 [two]=2) ; sv cfg
declare -A cfg='([one]="1" [two]="2" )'     #two elements

> cfg+=([two]=2 [three]=3) ; sv cfg            
declare -A cfg='([one]="1" [two]="22" [three]="3" )'  #Note key 'two'

> int cfg                                  # switch existing hash to integers.
                                           # explicitly use += in some
> cfg+=([one]+=1 [two]=2 [three]+=0-3 )    # VALUE assignments
> sv cfg
declare -Ai cfg='([one]="2" [two]="24" [three]="0" )'


Fix:
        Honor "=" to mean "set" and allow "+=" to continue to 
access this behavior.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]