Skip to content

Commit b3daec3

Browse files
committed
tools/gitlog2version.sh, tools/semver-compare.sh: fix numeric envvar/CLI arg evaluation for ksh [networkupstools#3055]
...where `[ '' -ge 0 ] ; echo $?` does not report a non-numeric error, but succeeds instead. Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent 954f707 commit b3daec3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tools/gitlog2version.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fi
167167

168168
##############################################################################
169169
# For tools/semver-compare.sh ($SEMVER_COMPARE):
170-
if [ "${NUT_VERSION_EXTRA_WIDTH-}" -gt 6 ] 2>/dev/null ; then
170+
if [ -n "${NUT_VERSION_EXTRA_WIDTH-}" -a "${NUT_VERSION_EXTRA_WIDTH-}" -gt 6 ] 2>/dev/null ; then
171171
:
172172
else
173173
NUT_VERSION_EXTRA_WIDTH=6
@@ -180,7 +180,7 @@ fi
180180

181181
# When padding extra width for e.g. comparisons, is 1.2.3 equal to 1.2.3.0.0?
182182
# Should we add those ".0" in the end?
183-
if [ "${NUT_VERSION_MIN_COMPONENTS-}" -ge 0 ] 2>/dev/null ; then
183+
if [ -n "${NUT_VERSION_MIN_COMPONENTS-}" -a "${NUT_VERSION_MIN_COMPONENTS-}" -ge 0 ] 2>/dev/null ; then
184184
# A number specified by caller is valid (positive integer)
185185
:
186186
else

tools/semver-compare.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ LC_ALL=C
2828
TZ=UTC
2929
export LANG LC_ALL TZ
3030

31-
if [ "${NUT_VERSION_EXTRA_WIDTH-}" -gt 6 ] 2>/dev/null ; then
31+
if [ -n "${NUT_VERSION_EXTRA_WIDTH-}" -a "${NUT_VERSION_EXTRA_WIDTH-}" -gt 6 ] 2>/dev/null ; then
3232
:
3333
else
3434
NUT_VERSION_EXTRA_WIDTH=6
3535
fi
3636

37-
if [ "${NUT_VERSION_MIN_COMPONENTS-}" -ge 0 ] 2>/dev/null ; then
37+
if [ -n "${NUT_VERSION_MIN_COMPONENTS-}" -a "${NUT_VERSION_MIN_COMPONENTS-}" -ge 0 ] 2>/dev/null ; then
3838
# A number specified by caller is valid (positive integer)
3939
:
4040
else
@@ -189,14 +189,14 @@ EOF
189189
exit 0
190190
;;
191191
--width|-w)
192-
if [ "$2" -ge 6 ]; then
192+
if [ -n "$2" -a "$2" -ge 6 ]; then
193193
NUT_VERSION_EXTRA_WIDTH="$2"
194194
fi
195195
# FIXME: "else" and error handling vs number too small and ignored?
196196
shift
197197
;;
198198
--min-components)
199-
if [ "$2" -ge 0 ]; then
199+
if [ -n "$2" -a "$2" -ge 0 ]; then
200200
NUT_VERSION_MIN_COMPONENTS="$2"
201201
fi
202202
# FIXME: "else" and error handling vs number too small and ignored?

0 commit comments

Comments
 (0)