Skip to content

Commit 4652daf

Browse files
committed
fix: Improve documentation and robustability of the defensive interpreter behavior setting logic
Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
1 parent edf953a commit 4652daf

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

basic.bash

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
# Copyright _copyright_effective_year_ _copyright_holder_name_ <_copyright_holder_contact_>
55
# SPDX-License-Identifier: CC-BY-SA-4.0
66

7-
set \
8-
-o errexit \
9-
-o errtrace \
7+
set_opts=(
8+
# Terminate script execution when an unhandled error occurs
9+
-o errexit
10+
-o errtrace
11+
12+
# Terminate script execution when an unset parameter variable is
13+
# referenced
1014
-o nounset
15+
)
16+
if ! set "${set_opts[@]}"; then
17+
printf \
18+
'Error: Unable to set the defensive interpreter behavior.\n' \
19+
1>&2
20+
exit 1
21+
fi
1122

1223
required_commands=(
1324
realpath

primitive.bash

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
# Copyright _copyright_effective_year_ _copyright_holder_name_ <_copyright_holder_contact_>
55
# SPDX-License-Identifier: CC-BY-SA-4.0
66

7-
set \
8-
-o errexit \
9-
-o errtrace \
7+
set_opts=(
8+
# Terminate script execution when an unhandled error occurs
9+
-o errexit
10+
-o errtrace
11+
12+
# Terminate script execution when an unset parameter variable is
13+
# referenced
1014
-o nounset
15+
)
16+
if ! set "${set_opts[@]}"; then
17+
printf \
18+
'Error: Unable to set the defensive interpreter behavior.\n' \
19+
1>&2
20+
exit 1
21+
fi

0 commit comments

Comments
 (0)