Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16694

Declaring arrays with empty string in one line is bugged

From andy_bash <andy_bash@objectmail.com>
Newsgroups gnu.bash.bug
Subject Declaring arrays with empty string in one line is bugged
Date 2020-08-04 19:31 +0200
Message-ID <mailman.806.1596565717.2739.bug-bash@gnu.org> (permalink)
References <1596562283.5f299b6be9c50@trashmail.com>

Show all headers | View raw


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:&nbsp; &nbsp; &nbsp; &nbsp; 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.
&nbsp; &nbsp; &nbsp; &nbsp; I first discovered this through a piece of indirection code I have:
&nbsp; &nbsp; &nbsp; &nbsp; x=("")&nbsp; &nbsp; &nbsp; &nbsp; y="x[@]"&nbsp; &nbsp; &nbsp; &nbsp; local z=(${!y+"${!y}"})
Repeat-By:&nbsp; &nbsp; &nbsp; &nbsp; 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'
&nbsp; &nbsp; &nbsp; &nbsp; Results:&nbsp; &nbsp; &nbsp; &nbsp; declare -a bug4=([0]="5" [1]="1")&nbsp; &nbsp; &nbsp; &nbsp; declare -a bug=([0]="5" [1]="1")&nbsp; &nbsp; &nbsp; &nbsp; declare -a bug2=()&nbsp; &nbsp; &nbsp; &nbsp; declare -a bug3=([0]="5" [1]="1")&nbsp; &nbsp; &nbsp; &nbsp; declare -a not_bug=([0]="no" [1]="nulls")&nbsp; &nbsp; &nbsp; &nbsp; declare -a workaround=([0]="")
&nbsp; &nbsp; &nbsp; &nbsp; As you can see, all the empty strings (null strings) are missing, except in the workaround
Fix:&nbsp; &nbsp; &nbsp; &nbsp; Declaring an array with empty strings ("") in one line should work, just like it did in bash 3.2-5.0
&nbsp; &nbsp; &nbsp; &nbsp; This original piece of code should also work the same as versions 3.2-5.0 too
&nbsp; &nbsp; &nbsp; &nbsp; $ 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'&nbsp; &nbsp; &nbsp; &nbsp; declare -a copy=([0]="" [1]="5" [2]="")&nbsp; &nbsp; &nbsp; &nbsp; declare -a copy=()
&nbsp; &nbsp; &nbsp; &nbsp; $ 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'&nbsp; &nbsp; &nbsp; &nbsp; declare -a copy=([0]="5")&nbsp; &nbsp; &nbsp; &nbsp; declare -a copy=()
Thanks,-Andy

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Declaring arrays with empty string in one line is bugged andy_bash <andy_bash@objectmail.com> - 2020-08-04 19:31 +0200

csiph-web