aboutsummaryrefslogtreecommitdiff
path: root/shflags
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2020-04-09 10:53:53 +0200
committerKate Ward <kate.ward@forestent.com>2020-04-09 10:53:53 +0200
commitd368f831e7db7e41aa95b5a4ea9817cfa952983b (patch)
treee13cb1257e9c43e19a1d04aed18f2e4994b62dfc /shflags
parent5a723f81f03f6c4f076b8a06a1f550d6a4767796 (diff)
downloadshflags-d368f831e7db7e41aa95b5a4ea9817cfa952983b.tar.gz
Fixed expr command determination to work with 'set -e'.
Diffstat (limited to 'shflags')
-rw-r--r--shflags31
1 files changed, 19 insertions, 12 deletions
diff --git a/shflags b/shflags
index e907ba7..46ca3d7 100644
--- a/shflags
+++ b/shflags
@@ -108,18 +108,25 @@ FLAGS_LEVEL_FATAL=4
__FLAGS_LEVEL_DEFAULT=${FLAGS_LEVEL_WARN}
# Determine some reasonable command defaults.
-__FLAGS_EXPR_CMD='expr --'
-__FLAGS_UNAME_S=`uname -s`
-if [ "${__FLAGS_UNAME_S}" = 'BSD' ]; then
- __FLAGS_EXPR_CMD='gexpr --'
-else
- _flags_output_=`${__FLAGS_EXPR_CMD} 2>&1`
- if [ $? -eq ${FLAGS_TRUE} -a "${_flags_output_}" = '--' ]; then
- # We are likely running inside BusyBox.
- __FLAGS_EXPR_CMD='expr'
+_flags_expr_cmd() {
+ if [ "$(uname -s)" = 'BSD' ]; then
+ echo 'gexpr --'
+ return 0
fi
- unset _flags_output_
-fi
+
+ _flags_expr_cmd_='expr --'
+ # shellcheck disable=SC2003
+ if _flags_output_=$(expr -- 2>&1); then
+ if [ "${_flags_output_}" = '--' ]; then
+ # We are likely running inside BusyBox.
+ _flags_expr_cmd_='expr'
+ fi
+ fi
+
+ echo "${_flags_expr_cmd_}"
+ unset _flags_expr_cmd_ _flags_output_
+}
+__FLAGS_EXPR_CMD=`_flags_expr_cmd`
# Commands a user can override if desired.
FLAGS_EXPR_CMD=${FLAGS_EXPR_CMD:-${__FLAGS_EXPR_CMD}}
@@ -1201,7 +1208,7 @@ flags_reset() {
unset flags_name_ flags_type_ flags_strToEval_ flags_usName_
}
-#
+#-----------------------------------------------------------------------------
# Initialization
#