[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] errexit and attempting to change readonly functions

From: Andreas Kusalananda Kähäri
Subject: [Help-bash] errexit and attempting to change readonly functions
Date: Fri, 27 Sep 2019 12:12:10 +0200
User-agent: Mutt/1.12.2 (2019-09-21)

A function can be made read-only with

    readonly -f func

This stops it from being unset or redefined:

    $ func () { echo hello; }
    bash: func: readonly function

However, with the errexit shell option set, I would expect the shell
to exit when doing this, just like it exits when trying to modify a
read-only variable under errexit:

    $ set -e
    $ func () { echo hello; }
    $ readonly -f func
    $ func () { echo hi; }
    bash: func: readonly function
    $ # I'm still here

    $ set -e
    $ readonly var=42
    $ var=32
    bash: var: readonly variable
    (shell terminates)

What's the rationale behind this, or is it a bug?  Or did I simply miss
some text in the manual?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]