Skip to content

Commit ad6b870

Browse files
committed
Bugfix minimum bash version check, with nifty idea
from Stack Exchange: https://unix.stackexchange.com/a/285928
1 parent 470914c commit ad6b870

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripting-utils.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ ensure_deps() {
4040
ensure_min_bash_version() {
4141
# Given a 'Major.Minor.Patch' SemVer number, return 1 if the system's
4242
# bash version is older than the given version. Default to 4.0.0.
43-
local semver=($(IFS='.' ; echo $1 ;));
44-
! [[ ${BASH_VERSINFO[0]} -lt ${semver[0]:-4} ||
45-
${BASH_VERSINFO[1]} -lt ${semver[1]:-0} ||
46-
${BASH_VERSINFO[2]} -lt ${semver[2]:-0} ]]
43+
# Hat tip: https://unix.stackexchange.com/a/285928
44+
local semver="${1:-4.0.0}"
45+
local bashver="${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}"
46+
47+
[[ $(printf "%s\n" ${semver} ${bashver} | sort -V | head -1) == ${semver} ]]
4748
}
4849

4950
#

0 commit comments

Comments
 (0)