From be94c6031662512e107822107274c45d7064e7f0 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Thu, 18 Jul 2024 15:02:16 -0700 Subject: [PATCH] fix how tools check exit codes an entire pipe We use the `status_codes=("${PIPESTATUS[@]}")` method to collect all of the bash exit codes from a pipe in one go, and then test for any failure with `[[ ${status_codes[*]} =~ [1-9] ]]`. There are other cases where an exit code is obtained, however in each of those cases only a single exit code from just one of the commands in the pipe is needed. In `bin/gen-sitemap.sh` changed VERSION from "1.3.9 2024-06-21" to "1.3.10 2024-07-18". In `bin/gen-status.sh` changed VERSION from "1.5.4 2024-07-18" to "1.5.5 2024-07-18". Performed `make www` to accomplish the above and to test under macOS. --- bin/gen-sitemap.sh | 18 +++++++++--------- bin/gen-status.sh | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bin/gen-sitemap.sh b/bin/gen-sitemap.sh index 9af23f263..38fac6e54 100755 --- a/bin/gen-sitemap.sh +++ b/bin/gen-sitemap.sh @@ -84,7 +84,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an # set variables referenced in the usage message # -export VERSION="1.3.9 2024-06-21" +export VERSION="1.3.10 2024-07-18" NAME=$(basename "$0") export NAME export V_FLAG=0 @@ -160,11 +160,11 @@ function output_modtime # RHEL_stat) TZ=UTC "$STAT_TOOL" -c '%y' "$FILENAME" | sed -e 's/ /T/' -e 's/\.[0-9]* //' -e 's/\([0-9][0-9]\)$/:&/' - status0="${PIPESTATUS[0]}" - status1="${PIPESTATUS[1]}" - if [[ $status0 -ne 0 || $status1 -ne 0 ]]; then + status_codes=("${PIPESTATUS[@]}") + if [[ ${status_codes[*]} =~ [1-9] ]]; then echo "$0: ERROR: in output_modtime:" \ - "TZ=UTC $STAT_TOOL -c '%y' $FILENAME | sed .. failed, error codes: $status0 and $status1" 1>&2 + "TZ=UTC $STAT_TOOL -c '%y' $FILENAME | sed .. failed," \ + "error codes: ${status_codes[*]}" 1>&2 exit 1 fi ;; @@ -175,12 +175,12 @@ function output_modtime # SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames. # https://www.shellcheck.net/wiki/SC2012 # shellcheck disable=SC2012 + status_codes=("${PIPESTATUS[@]}") + if [[ ${status_codes[*]} =~ [1-9] ]]; then TZ=UTZ "$LS_TOOL" -D '%FT%T+00:00' -ld "$FILENAME" | awk '{print $6;}' - status0="${PIPESTATUS[0]}" - status1="${PIPESTATUS[1]}" - if [[ $status0 -ne 0 || $status1 -ne 0 ]]; then echo "$0: ERROR: in output_modtime:" \ - "TZ=UTZ $LS_TOOL -D '%FT%T+00:00' -ld $FILENAME | awk .. failed, error codes: $status0 and $status1" 1>&2 + "TZ=UTZ $LS_TOOL -D '%FT%T+00:00' -ld $FILENAME | awk .. failed," \ + "error codes: ${status_codes[*]}" 1>&2 exit 1 fi ;; diff --git a/bin/gen-status.sh b/bin/gen-status.sh index 70e9230fb..7072fa37a 100755 --- a/bin/gen-status.sh +++ b/bin/gen-status.sh @@ -84,7 +84,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an # set variables referenced in the usage message # -export VERSION="1.5.4 2024-07-18" +export VERSION="1.5.5 2024-07-18" NAME=$(basename "$0") export NAME export V_FLAG=0 @@ -178,11 +178,11 @@ function output_modtime # RHEL_stat) TZ=UTC "$STAT_TOOL" -c '%y' "$FILENAME" | sed -e 's/ /T/' -e 's/\.[0-9]* //' -e 's/\([0-9][0-9]\)$/:&/' - status0="${PIPESTATUS[0]}" - status1="${PIPESTATUS[1]}" - if [[ $status0 -ne 0 || $status1 -ne 0 ]]; then + status_codes=("${PIPESTATUS[@]}") + if [[ ${status_codes[*]} =~ [1-9] ]]; then echo "$0: ERROR: in output_modtime:" \ - "TZ=UTC $STAT_TOOL -c '%y' $FILENAME | sed .. failed, error codes: $status0 and $status1" 1>&2 + "TZ=UTC $STAT_TOOL -c '%y' $FILENAME | sed .. failed," \ + "error codes: ${status_codes[*]}" 1>&2 exit 1 fi ;; @@ -194,11 +194,11 @@ function output_modtime # https://www.shellcheck.net/wiki/SC2012 # shellcheck disable=SC2012 TZ=UTZ "$LS_TOOL" -D '%FT%T+00:00' -ld "$FILENAME" | awk '{print $6;}' - status0="${PIPESTATUS[0]}" - status1="${PIPESTATUS[1]}" - if [[ $status0 -ne 0 || $status1 -ne 0 ]]; then + status_codes=("${PIPESTATUS[@]}") + if [[ ${status_codes[*]} =~ [1-9] ]]; then echo "$0: ERROR: in output_modtime:" \ - "TZ=UTZ $LS_TOOL -D '%FT%T+00:00' -ld $FILENAME | awk .. failed, error codes: $status0 and $status1" 1>&2 + "TZ=UTZ $LS_TOOL -D '%FT%T+00:00' -ld $FILENAME | awk .. failed," \ + "error codes: ${status_codes[*]}" 1>&2 exit 1 fi ;;