From 4652dafd43b64a41df5b7bef95e917b683860228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=8D=9A=E4=BB=81=28Buo-ren=2C=20Lin=29?= Date: Thu, 30 Nov 2023 11:56:45 +0800 Subject: [PATCH] fix: Improve documentation and robustability of the defensive interpreter behavior setting logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ๆž—ๅšไป(Buo-ren, Lin) --- basic.bash | 17 ++++++++++++++--- primitive.bash | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/basic.bash b/basic.bash index bb6aaf0..050bd40 100755 --- a/basic.bash +++ b/basic.bash @@ -4,10 +4,21 @@ # Copyright _copyright_effective_year_ _copyright_holder_name_ <_copyright_holder_contact_> # SPDX-License-Identifier: CC-BY-SA-4.0 -set \ - -o errexit \ - -o errtrace \ +set_opts=( + # Terminate script execution when an unhandled error occurs + -o errexit + -o errtrace + + # Terminate script execution when an unset parameter variable is + # referenced -o nounset +) +if ! set "${set_opts[@]}"; then + printf \ + 'Error: Unable to set the defensive interpreter behavior.\n' \ + 1>&2 + exit 1 +fi required_commands=( realpath diff --git a/primitive.bash b/primitive.bash index 96470a2..1388efb 100755 --- a/primitive.bash +++ b/primitive.bash @@ -4,7 +4,18 @@ # Copyright _copyright_effective_year_ _copyright_holder_name_ <_copyright_holder_contact_> # SPDX-License-Identifier: CC-BY-SA-4.0 -set \ - -o errexit \ - -o errtrace \ +set_opts=( + # Terminate script execution when an unhandled error occurs + -o errexit + -o errtrace + + # Terminate script execution when an unset parameter variable is + # referenced -o nounset +) +if ! set "${set_opts[@]}"; then + printf \ + 'Error: Unable to set the defensive interpreter behavior.\n' \ + 1>&2 + exit 1 +fi