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


Groups > gnu.bash.bug > #16696

Re: Declaring arrays with empty string in one line is bugged

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Koichi Murase <myoga.murase@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Declaring arrays with empty string in one line is bugged
Date Wed, 5 Aug 2020 03:55:26 +0900
Lines 91
Approved bug-bash@gnu.org
Message-ID <mailman.811.1596567343.2739.bug-bash@gnu.org> (permalink)
References <1596562283.5f299b6be9c50@trashmail.com> <CAFLRLk8bwzMj1jT0Epmkfpd85QOq=PKB-VW8DKow1xDZ9VAHOQ@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1596567344 28302 209.51.188.17 (4 Aug 2020 18:55:44 GMT)
X-Complaints-To action@cs.stanford.edu
Cc chet@cwru.edu, bash-testers@cwru.edu, bug-bash@gnu.org
To andy_bash <andy_bash@objectmail.com>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zCCj6vj9xtLCWZ2YzGL17xDkyhiQQ+akTUiTj8OxVLQ=; b=NBgYDxOTuoja0oT+Y3+3u+TY1xIyyyj5Es6aX2mqifvxacgA1bbXYaYy08Au6JJx02 zv/YLASZSZ42tGSwfJ/3Gpgt6wKqFDnjwVg9IGlT2RHEtvOCpghlG0Z0D1fxi6DDkhqJ RSFjx03jLTulBskg1fAzeVvXl1Vs7XZFCQiddDNJm6WngO9MJBkeYQS7XJpRllt+iFZp zGz6ZK+hymN5emSFOpj872TgQa6DNIw+l2XdxnrZmG83n16GRItrN19jOSqA6pJCq3Ce YMdfFivEQ5HMG7YcX7cseD2GBYb5tYYDxhDIPNKRDTLSmBNoQtGFReN+RUxanBxcAOZb OBaA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zCCj6vj9xtLCWZ2YzGL17xDkyhiQQ+akTUiTj8OxVLQ=; b=qAjjW4WRoZ3ZmV3hjB4hsKUI3LTbSLz4Wpv2BE1WLGhO+zlnn4z0RNHCm32PHZhnk4 fzE5krqf8BqUTX9VsIPLnPVdvGIAak6RHI/68v2d+vFtNP1OdCSbbIZtyItR5D/ujnGe JV43MFws2f1aZZVRopiMYySlRUAAEmycUo5sU32+hKlqbB9a6xCCupDVmAI8Ou/XXmfy JoqhL2YuhC4o8qLxrUU/mpwCzmcWwvz339rEtcMRaXjQ6HfOU1PCKLZbIumZiS7QoYV0 4l8pH1Yk0D5WXm2sxlHBsYw56Rrsp5O3El3YBuJVFg1uvovlK6yQqijqPlFemQdLKI94 H62A==
X-Gm-Message-State AOAM533wMT37eWTxgwPxnv9MLzBgFMs+o8DFktTR79TEgMroZgi3/oYJ RHscuGpuRftuKLoifHIk6vYJEHhsmNbLLbwbxsw=
X-Google-Smtp-Source ABdhPJyZxw7HEfR5I0qG2PYPcuMMa0c6Mqk6k6o33p21rMWsqxRKHl9TKHTLEAHjx/zL3MDb1FoVDP3gsgS9ECCq/WE=
X-Received by 2002:ac2:5223:: with SMTP id i3mr11837746lfl.57.1596567338260; Tue, 04 Aug 2020 11:55:38 -0700 (PDT)
In-Reply-To <1596562283.5f299b6be9c50@trashmail.com>
Received-SPF pass client-ip=2a00:1450:4864:20::12d; envelope-from=myoga.murase@gmail.com; helo=mail-lf1-x12d.google.com
X-detected-operating-system by eggs.gnu.org: No matching host in p0f cache. That's all we know.
X-Spam_score_int -20
X-Spam_score -2.1
X-Spam_bar --
X-Spam_report (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action no action
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAFLRLk8bwzMj1jT0Epmkfpd85QOq=PKB-VW8DKow1xDZ9VAHOQ@mail.gmail.com>
X-Mailman-Original-References <1596562283.5f299b6be9c50@trashmail.com>
Xref csiph.com gnu.bash.bug:16696

Show key headers only | View raw


It also reproduces in the current devel branch.

$ bash-dev -c 'declare -a arr=(""); declare -p arr'
declare -a arr=()
$ bash-5.0 -c 'declare -a arr=(""); declare -p arr'
declare -a arr=([0]="")

2020-08-05 3:33 andy_bash <andy_bash@objectmail.com>:
> Sorry, the colors got messed up on the last email

It's still messed up. I reformatted:

> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64OS: linux-musl
> Compiler: gcc
> Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
> uname output: Linux 37b7613044c1 5..5.7-200.fc31.x86_64 #1 SMP Fri Feb
> 28 17:18:37 UTC 2020 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-musl
> Bash Version: 5.1Patch Level: 0
> Release 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

--
Koichi

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


Thread

Re: Declaring arrays with empty string in one line is bugged Koichi Murase <myoga.murase@gmail.com> - 2020-08-05 03:55 +0900

csiph-web