Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16692
| Path | csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | andy_bash <andy_bash@objectmail.com> |
| 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 | <mailman.804.1596565715.2739.bug-bash@gnu.org> (permalink) |
| 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 <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 | <1596560859.5f2995dbe7dcf@trashmail.com> |
| Xref | csiph.com gnu.bash.bug:16692 |
Show key headers only | View raw
​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=()
Back to gnu.bash.bug | Previous | Next | Find similar
Declaring arrays with empty string in one line is bugged andy_bash <andy_bash@objectmail.com> - 2020-08-04 19:07 +0200
csiph-web