commit:     c4db6fbdb626865063943a4b969c887211ab393f
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Aug 16 06:27:58 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Aug 22 19:37:46 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=c4db6fbd

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 <AT> plushkava.net>

 functions.sh | 18 +++++++++++++++---
 1 file 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"

Reply via email to