commit: 786a135634a062f3eb1c1dc46e8e46a9f22aba57 Author: Kerin Millar <kfm <AT> plushkava <DOT> net> AuthorDate: Mon Feb 13 03:11:44 2023 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Mon Feb 13 21:35:26 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=786a1356
Add an _is_visible() function and use it internally Joining one or more positional parameters by the first character of IFS then checking whether the resulting string has a length of zero, is not an effective way of determining whether the collective message is blank. This implements a helper function that implements the check in the fashion that was seemingly intended. Signed-off-by: Kerin Millar <kfm <AT> plushkava.net> Signed-off-by: Sam James <sam <AT> gentoo.org> functions.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/functions.sh b/functions.sh index 9bae772..2361808 100644 --- a/functions.sh +++ b/functions.sh @@ -91,12 +91,11 @@ esyslog() tag=$2 shift 2 msg=$* - case ${msg} in - *[[:graph:]]*) - # This is not strictly portable because POSIX - # defines no options whatsoever for logger(1). - logger -p "${pri}" -t "${tag}" -- "${msg}" - esac + if _is_visible "${msg}"; then + # This is not strictly portable because POSIX defines + # no options whatsoever for logger(1). + logger -p "${pri}" -t "${tag}" -- "${msg}" + fi fi } @@ -244,7 +243,7 @@ _eend() shift 2 if [ "${retval}" != "0" ]; then - if [ -n "$*" ]; then + if _is_visible "$*"; then "${efunc}" "$*" fi msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}" @@ -431,6 +430,14 @@ is_int() { esac } +# +# Determine whether the first operand contains any visible characters. This +# is intended to be a private function. +# +_is_visible() { + ! case $1 in *[[:graph:]]*) false ;; esac +} + # This is the main script, please add all functions above this point! # Dont output to stdout?