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


Groups > gnu.bash.bug > #14829

Misbehavior with constants and bash script

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Alexander Reintzsch <Alexander.Reintzsch@netsystem.de>
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 <mailman.4276.1542667293.1284.bug-bash@gnu.org> (permalink)
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" <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 <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://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>
Xref csiph.com gnu.bash.bug:14829

Show key headers only | View raw


Hello,

I think I have found some unexpected behavior related to constants in
bash scripts. Here is a bash script as a short proof of concept.

#!/bin/bash
function foo
{
        echo "A"
        declare -r vconst="I am fixed."
        echo "B"
        declare vconst="new value"
        echo "C"
        unset vconst
        echo "D"
        vconst="new value"
        echo "E" # not executed
}

function bar
{
        echo "before foo"
        foo
        echo "after foo" # not executed
}

function buzz
{
        echo "before bar"
        bar
        echo "after bar" # not executed
}

foo
bar
buzz
echo "the last line"

Usually bash scripts continue with the next command if they face an error with one command
but this script shows some weird behavior. It exits all the functions
it has called without executing the remaining commands and the continues
to run in the top scope of the script.

This only happens when a constant declared with
declare -r myConst="myConstantValue"
is attempted to be redefined using
myConst="new value"
but not with
declare myConst="new value"

This behavior doesn't seem right.

I have tried this on Ubuntu 16.04 LTS with bash version
GNU bash, Version 4.3.48(1)-release (x86_64-pc-linux-gnu)

Cheers,
Alex

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


Thread

Misbehavior with constants and bash script Alexander Reintzsch <Alexander.Reintzsch@netsystem.de> - 2018-11-19 21:44 +0000

csiph-web