Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: andy_bash Newsgroups: gnu.bash.bug Subject: Declaring arrays with empty string in one line is bugged Date: Tue, 04 Aug 2020 19:07:39 +0200 Lines: 49 Approved: bug-bash@gnu.org Message-ID: References: <1596560859.5f2995dbe7dcf@trashmail.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1596565716 27100 209.51.188.17 (4 Aug 2020 18:28:36 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: chet@cwru.edu, bash-testers@cwru.edu Envelope-to: bug-bash@gnu.org Received-SPF: pass client-ip=116.202.184.113; envelope-from=andy_bash@objectmail.com; helo=b.mxout.trashmail.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/04 13:07:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 04 Aug 2020 14:28:33 -0400 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1596560859.5f2995dbe7dcf@trashmail.com> Xref: csiph.com gnu.bash.bug:16692 =E2=80=8BConfiguration Information [Automatically generated, do not chan= ge]: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/Linu= xMachine Type: x86_64-pc-linux-musl Bash Version: 5.1Patch Level: 0Re= lease Status: alpha Description:        Declaring= an array and setting it with empty strings ("") in one line is bugged i= n bash 5.1 alpha. This has worked in bash 3.2-5.0 without issue. &nb= sp;       I first discovered this through a piece of indi= rection code I have:         x=3D("")   =     y=3D"x[@]"        local z=3D(${!y+"${= !y}"}) Repeat-By:        docker run -it --r= m bash:5.1-alpha bash -c 'function foo(){ local bug=3D("" "5" "" 1 ""); de= clare -a bug2=3D(""); declare -ga bug3=3D("" "5" "" 1 ""); local not_bug= =3D("no" "nulls"); local workaround; workaround=3D(""); declare -p bug b= ug2 bug3 not_bug workaround; }; declare -a bug4=3D("" "5" "" 1 ""); declar= e -p bug4; foo'         Results:   = ;     declare -a bug4=3D([0]=3D"5" [1]=3D"1")     = ;   declare -a bug=3D([0]=3D"5" [1]=3D"1")       = declare -a bug2=3D()        declare -a bug3=3D([0]=3D= "5" [1]=3D"1")        declare -a not_bug=3D([0]=3D"no"= [1]=3D"nulls")        declare -a workaround=3D([0]=3D= "")         As you can see, all the empty= strings (null strings) are missing, except in the workaround Fix:&n= bsp;       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=3D"${1}[@]"; local c= opy=3D(${!name+"${!name}"}); declare -p copy; }; x=3D("" 5 ""); foo x; f= oo undeclared_x'        declare -a copy=3D([0]=3D"" = [1]=3D"5" [2]=3D"")        declare -a copy=3D() &n= bsp;       $ docker run -it --rm bash:5.1-alpha bash -euc= 'function foo(){ local name=3D"${1}[@]"; local copy=3D(${!name+"${!name= }"}); declare -p copy; }; x=3D("" 5 ""); foo x; foo undeclared_x'  &n= bsp;     declare -a copy=3D([0]=3D"5")      &nb= sp; declare -a copy=3D()