Re: ${assoc[key]+set} no longer works.
2014-03-18 16:19 GMT+01:00 Chet Ramey chet.ra...@case.edu: On 3/18/14 5:36 AM, geir.ha...@gmail.com wrote: Bash Version: 4.3 Patch Level: 0 Release Status: release Description: With an associative array, assoc, ${assoc[key]+set} expands to the empty string if the associated value is the empty string. Thanks for the report. This was a consequence of a change made back in 2011 to expand the value portion of the assignment statement a slightly different way. I've attached a patch to fix it. Thanks. That patch also makes [[ -v assoc[x] ]] return 0. However, [[ -v assoc ]] returns 1 (which it also does before the patch). Sounds related to this bug. -- Geir Hauge
Re: ${assoc[key]+set} no longer works.
On 3/19/14, 5:42 PM, Geir Hauge wrote: Description: With an associative array, assoc, ${assoc[key]+set} expands to the empty string if the associated value is the empty string. Thanks for the report. This was a consequence of a change made back in 2011 to expand the value portion of the assignment statement a slightly different way. I've attached a patch to fix it. Thanks. That patch also makes [[ -v assoc[x] ]] return 0. However, [[ -v assoc ]] returns 1 (which it also does before the patch). Sounds related to this bug. That's not a bug. Referencing any array without a subscript is equivalent to referencing subscript 0. In the case of an associative array, that's ${assoc[0]}. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
${assoc[key]+set} no longer works.
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-unknown-linux-gnu' -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -O2 uname output: Linux gina 3.2.0-59-generic #90-Ubuntu SMP Tue Jan 7 22:43:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-unknown-linux-gnu Bash Version: 4.3 Patch Level: 0 Release Status: release Description: With an associative array, assoc, ${assoc[key]+set} expands to the empty string if the associated value is the empty string. Repeat-By: $ declare -A assoc='([x]= [y]=1 )' $ printf '%s\n' ${assoc[x]+x is a key} ${assoc[y]+y is a key} y is a key
Re: ${assoc[key]+set} no longer works.
On 3/18/14 5:36 AM, geir.ha...@gmail.com wrote: Bash Version: 4.3 Patch Level: 0 Release Status: release Description: With an associative array, assoc, ${assoc[key]+set} expands to the empty string if the associated value is the empty string. Thanks for the report. This was a consequence of a change made back in 2011 to expand the value portion of the assignment statement a slightly different way. I've attached a patch to fix it. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/ *** ../bash-4.3/arrayfunc.c 2013-08-02 16:19:59.0 -0400 --- arrayfunc.c 2014-03-18 11:08:15.0 -0400 *** *** 598,601 --- 598,606 { val = expand_assignment_string_to_string (val, 0); + if (val == 0) + { + val = (char *)xmalloc (1); + val[0] = '\0'; /* like do_assignment_internal */ + } free_val = 1; }