bug-bash
[Top][All Lists]
Advanced

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

Declaring arrays with empty string in one line is bugged


From: andy_bash
Subject: Declaring arrays with empty string in one line is bugged
Date: Tue, 04 Aug 2020 19:31:23 +0200

Sorry, the colors got messed up on the last email
​Configuration Information [Automatically generated, do not change]:Machine: 
x86_64OS: linux-muslCompiler: gccCompilation CFLAGS: -g -O2 -Wno-parentheses 
-Wno-format-securityuname output: Linux 37b7613044c1 5.5.7-200.fc31.x86_64 #1 
SMP Fri Feb 28 17:18:37 UTC 2020 x86_64 GNU/LinuxMachine Type: 
x86_64-pc-linux-musl
Bash Version: 5.1Patch Level: 0Release Status: alpha
Description:        Declaring an array and setting it with 
empty strings ("") in one line is bugged in bash 5.1 alpha.. This has worked in 
bash 3.2-5.0 without issue.
        I first discovered this through a piece of 
indirection code I have:
        x=("")        y="x[@]"  
      local z=(${!y+"${!y}"})
Repeat-By:        docker run -it --rm bash:5.1-alpha bash 
-c 'function foo(){ local bug=("" "5" "" 1 ""); declare -a bug2=(""); declare 
-ga bug3=("" "5" "" 1 ""); local not_bug=("no" "nulls"); local workaround; 
workaround=(""); declare -p bug bug2 bug3 not_bug workaround; }; declare -a 
bug4=("" "5" "" 1 ""); declare -p bug4; foo'
        Results:        declare -a 
bug4=([0]="5" [1]="1")        declare -a bug=([0]="5" 
[1]="1")        declare -a bug2=()      
  declare -a bug3=([0]="5" [1]="1")        declare -a 
not_bug=([0]="no" [1]="nulls")        declare -a 
workaround=([0]="")
        As you can see, all the empty strings (null 
strings) are missing, except in the workaround
Fix:        Declaring an array with empty strings ("") in 
one line should work, just like it did in bash 3.2-5.0
        This original piece of code should also work the 
same as versions 3.2-5.0 too
        $ docker run -it --rm bash:5.0 bash -euc 'function 
foo(){ local name="${1}[@]"; local copy=(${!name+"${!name}"}); declare -p copy; 
}; x=("" 5 ""); foo x; foo undeclared_x'        declare -a 
copy=([0]="" [1]="5" [2]="")        declare -a copy=()
        $ docker run -it --rm bash:5.1-alpha bash -euc 
'function foo(){ local name="${1}[@]"; local copy=(${!name+"${!name}"}); 
declare -p copy; }; x=("" 5 ""); foo x; foo undeclared_x'      
  declare -a copy=([0]="5")        declare -a copy=()
Thanks,-Andy


reply via email to

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