Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Alexander Reintzsch Newsgroups: gnu.bash.bug Subject: Misbehavior with constants and bash script Date: Mon, 19 Nov 2018 21:44:38 +0000 Lines: 59 Approved: bug-bash@gnu.org Message-ID: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1542667294 29364 208.118.235.17 (19 Nov 2018 22:41:34 GMT) X-Complaints-To: action@cs.stanford.edu To: "bug-bash@gnu.org" Envelope-to: bug-bash@gnu.org Thread-Topic: Misbehavior with constants and bash script Thread-Index: AQHUgFCV52FarQ25FEyVUgBqSU7e5Q== Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [213.240.145.119] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 85.13.147.64 X-Mailman-Approved-At: Mon, 19 Nov 2018 17:41:32 -0500 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14829 Hello,=0A= =0A= I think I have found some unexpected behavior related to constants in=0A= bash scripts. Here is a bash script as a short proof of concept.=0A= =0A= #!/bin/bash=0A= function foo=0A= {=0A= echo "A"=0A= declare -r vconst=3D"I am fixed."=0A= echo "B"=0A= declare vconst=3D"new value"=0A= echo "C"=0A= unset vconst=0A= echo "D"=0A= vconst=3D"new value"=0A= echo "E" # not executed=0A= }=0A= =0A= function bar=0A= {=0A= echo "before foo"=0A= foo=0A= echo "after foo" # not executed=0A= }=0A= =0A= function buzz=0A= {=0A= echo "before bar"=0A= bar=0A= echo "after bar" # not executed=0A= }=0A= =0A= foo=0A= bar=0A= buzz=0A= echo "the last line"=0A= =0A= Usually bash scripts continue with the next command if they face an error w= ith one command=0A= but this script shows some weird behavior. It exits all the functions=0A= it has called without executing the remaining commands and the continues=0A= to run in the top scope of the script.=0A= =0A= This only happens when a constant declared with=0A= declare -r myConst=3D"myConstantValue"=0A= is attempted to be redefined using=0A= myConst=3D"new value"=0A= but not with=0A= declare myConst=3D"new value"=0A= =0A= This behavior doesn't seem right.=0A= =0A= I have tried this on Ubuntu 16.04 LTS with bash version=0A= GNU bash, Version 4.3.48(1)-release (x86_64-pc-linux-gnu)=0A= =0A= Cheers,=0A= Alex=