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:31:23 +0200 Lines: 51 Approved: bug-bash@gnu.org Message-ID: References: <1596562283.5f299b6be9c50@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 1596565717 27102 209.51.188.17 (4 Aug 2020 18:28:37 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=109.230.236.46; envelope-from=andy_bash@objectmail.com; helo=a.mxout.trashmail.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/04 13:31:24 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: 6 X-Spam_score: 0.6 X-Spam_bar: / X-Spam_report: (0.6 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_MSPIKE_BL=0.01, RCVD_IN_MSPIKE_L5=2.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: <1596562283.5f299b6be9c50@trashmail.com> Xref: csiph.com gnu.bash.bug:16694 Sorry, the colors got messed up on the last email =E2=80=8BConfigura= tion Information [Automatically generated, do not change]:Machine: x86_6= 4OS: 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: alp= ha Description:        Declaring an array and se= tting 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 h= ave:         x=3D("")        y= =3D"x[@]"        local z=3D(${!y+"${!y}"}) Repea= t-By:        docker run -it --rm bash:5.1-alpha bash= -c 'function foo(){ local bug=3D("" "5" "" 1 ""); declare -a bug2=3D(""= ); declare -ga bug3=3D("" "5" "" 1 ""); local not_bug=3D("no" "nulls"); = local workaround; workaround=3D(""); declare -p bug bug2 bug3 not_bug work= around; }; declare -a bug4=3D("" "5" "" 1 ""); declare -p bug4; foo' &= nbsp;       Results:        declare -= a bug4=3D([0]=3D"5" [1]=3D"1")        declare -a b= ug=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")&nbs= p;       declare -a workaround=3D([0]=3D"")   &n= bsp;     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, ju= st like it did in bash 3.2-5.0         This orig= inal piece of code should also work the same as versions 3.2-5.0 too=         $ docker run -it --rm bash:5.0 bash -eu= c 'function foo(){ local name=3D"${1}[@]"; local copy=3D(${!name+"${!nam= e}"}); declare -p copy; }; x=3D("" 5 ""); foo x; foo undeclared_x'  &= nbsp;     declare -a copy=3D([0]=3D"" [1]=3D"5" [2]=3D"") = ;       declare -a copy=3D()        = ; $ 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'        decla= re -a copy=3D([0]=3D"5")        declare -a copy=3D= () Thanks,-Andy