Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Binarus Newsgroups: gnu.bash.bug Subject: Re: Incorrect / Inconsistent behavior with nameref assignments in functions Date: Sat, 29 Aug 2020 07:45:44 +0200 Lines: 61 Approved: bug-bash@gnu.org Message-ID: References: <5f512e22-fe55-7281-7585-7cffb74299dc@binarus.de> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1598679952 6755 209.51.188.17 (29 Aug 2020 05:45:52 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bash@packages.debian.org To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=binarus.de; s=b201601; t=1598679944; bh=tDmdmTvbKNHMA07eJUUsTxaFmjH2e4w5/HnvdNE4sJQ=; h=Subject:Cc:References:From:To:Date:In-Reply-To:From:Reply-To: Subject:Date:To:Cc:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; b=SOju+h85CnW0Ay22sF4yUHLvPeN/JBBlvVfiyoQHlsKGjY76CQB1RfVDbWnFoPLrw dv8Vq2q3WJWyAYLTErn7keLajgEUQdJ7AweDSiMKqLGcdm2QKGdP7hSM9NGIQfEp44 Cu4hWdBJbr2V3OdFKTY6ndUSrZ1oXlBoX3FSbksgRhc+AFNuJIwGuTZU0mJqMLRcP8 8QN+1zaMNUsudRf4f7eGR1AARXaKECVmLtKdujFuXZo1RLxCknsvDl/8oT6iguvhiy cWqCq2eyEX3wCRpFt9e4xraTWh1SRLbIw+5/alOHpmjvaVwa77C0nCLigTx66HAcz/ PhElXe6yl/RymOeAw0Qw3M3a5Z+YYsqhiX38JEZY1GqxdV6axWnDnctVCYyVrtYbH/ teoNjVavh1WNcyY+tD56X0dJE9WNTG0shb2k7PHLBqDqfQ6W4ZofObLc4NMmIRb+yR DxxugqfrAes8g9c0pCfO96wT4JQ0jW/GYpoNjzfRlNx5tro7IFNdhOsm988yVxihmB ANC7oaQrYVhwbWIQBYvLMRLE2PA+6+Y8cFz+Ftu23aA8H8YIueWiFz5J9VUPhvuWNW oltnafYJNzF/GWBJ43XZmAtyhLgBLIAv9tXpwsKqhvOYo0L2gkcj3TDEvinI25gC27 flfjG//bHr7JSiIGLiy2tPIM= User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 In-Reply-To: Content-Language: en-US X-Bin-MAIL-FROM: X-Bin-RCPT-TO: Received-SPF: pass client-ip=144.76.90.229; envelope-from=lists@binarus.de; helo=odysseus.binarus.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/29 00:58:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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, NICE_REPLY_A=-0.809, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <5f512e22-fe55-7281-7585-7cffb74299dc@binarus.de> X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:16840 Thank you very much for your effort, testing and support! On 29.08.2020 01:46, Koichi Murase wrote: > 2020-08-28 22:04 Binarus : >> Description: >> ------------ >> >> Under certain circumstances, assignments of namerefs to local variables >> in functions behaves in a way which makes namerefs completely useless. >> Furthermore, the behavior is not consistent. > > This is actually not related to namerefs and has already been fixed in > Bash 5.1 and the devel branch. Think about the following codes: > > a=1; f1() { local a=$a; local; }; f1 > a=2; f2() { local -a a=("$a"); local; }; f2 > > The results for `f1' are the same for all the Bash versions > 2.0..devel, but the results for `f2' varies in versions. Here is the > summary of the results from the different versions of Bash: > > - 2.0..3.0: f1: a=1, f2: a=([0]="1") > - 3.1: f2: a=1, f2: a=([0]="") > - 3.2..4.2: f1: a=1, f2: a=([0]="1") > - 4.3..5.0: f1: a=1, f2: a=([0]="") > - 5.1..dev: f1: a=1, f2: a=([0]="1") This is very interesting. I never have written code like that and therefore had my problem not before making heavy use of namerefs. So I have tested my code in three different bash versions which all are buggy ... I am surprised that a bug of such severity could survive several years. I don't know when 4.3 came out, but my version of 4.4 is from 2016, and 5.1 is not out yet, so the bug survived at least 4 years (not taking into account devel or beta versions, which are not an option for most people). > I checked the detailed changes. The behavior of `f2' in 3.1 was > reported as a bug in the following thread. > > https://lists.gnu.org/archive/html/bug-bash/2006-05/msg00025.html > > It was fixed in 8b35878f (commit bash-20060504 snapshot). However, > the bug seems to be introduced again in 36eb585c (commit bash-20121221 > snapshot). This regression has been reported at > > https://savannah.gnu.org/support/index.php?109669 > > Finally, it was again fixed in c6c7ae81 (commit bash-20200427 > snapshot). Thank you very much again for that invaluable information! I am wondering when debian will include bash 5.1. It looks like debian testing and debian unstable are on bash 5.0, so it will probably take several years. Best regards, Binarus