diff options
author | Kerin Millar <kfm@plushkava.net> | 2024-08-16 07:27:58 +0100 |
---|---|---|
committer | Kerin Millar <kfm@plushkava.net> | 2024-08-22 20:37:46 +0100 |
commit | c4db6fbdb626865063943a4b969c887211ab393f (patch) | |
tree | e32e914ca178ded0e2977a3886ed4e0eb645b9dd | |
parent | Double quote a ${parameter+word} expansion in defer() (diff) | |
download | gentoo-functions-c4db6fbdb626865063943a4b969c887211ab393f.tar.gz gentoo-functions-c4db6fbdb626865063943a4b969c887211ab393f.tar.bz2 gentoo-functions-c4db6fbdb626865063943a4b969c887211ab393f.zip |
Warn upon sourcing if errexit or nounset be enabled
I am unwilling to pander to those that elect to enable either of the
errexit or nounset options. Rather than gloss over the matter, comment
as to the behaviour of gentoo-functions being unspecified in that event.
Further, display a warning for each of those options found to be enabled
at the time of sourcing functions.sh.
It is worth noting that the behaviour of nounset can be selectively
employed with the ${parameter:?} form of parameter expansion. Such is
occasionally useful and does not require for library authors to
acquiesce to the cult of the "unofficial strict mode".
Signed-off-by: Kerin Millar <kfm@plushkava.net>
-rw-r--r-- | functions.sh | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/functions.sh b/functions.sh index 8180182..2e2916b 100644 --- a/functions.sh +++ b/functions.sh @@ -10,9 +10,11 @@ # and to reduce the probability of name space conflicts. # The functions shall be compatible with the POSIX-1.2018 Shell and Utilities -# (XCU), except where otherwise noted, and with the additional exception that -# the use of the local utility is permitted, despite the results of its -# invocation being formally unspecified. +# (XCU), except where otherwise noted and with the exception that the use of +# the local utility is permitted, despite the results of its invocation being +# formally unspecified. Should either of the errexit and nounset options be +# enabled in the shell, the behaviour of gentoo-functions as a whole shall be +# unspecified. # The following variables affect initialisation and/or function behaviour. @@ -43,6 +45,16 @@ warn() printf '%s: %s\n' "${0##*/}" "$*" >&2 } +case $- in *e*) + # https://lists.gnu.org/archive/html/help-bash/2020-04/msg00049.html + warn "gentoo-functions does not support the errexit option; unexpected behaviour may ensue" +esac + +case $- in *u*) + # https://lists.gnu.org/archive/html/help-bash/2020-04/msg00049.html + warn "gentoo-functions does not support the nounset option; unexpected behaviour may ensue" +esac + case ${KSH_VERSION} in 'Version AJM 93'*) # The ksh93 shell has a typeset builtin but no local builtin. warn "gentoo-functions does not currently support ksh93" |