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


Groups > gnu.bash.bug > #14829 > unrolled thread

Misbehavior with constants and bash script

Started byAlexander Reintzsch <Alexander.Reintzsch@netsystem.de>
First post2018-11-19 21:44 +0000
Last post2018-11-19 21:44 +0000
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug


Contents

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

#14829 — Misbehavior with constants and bash script

FromAlexander Reintzsch <Alexander.Reintzsch@netsystem.de>
Date2018-11-19 21:44 +0000
SubjectMisbehavior with constants and bash script
Message-ID<mailman.4276.1542667293.1284.bug-bash@gnu.org>
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

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web