Last active
November 18, 2020 12:21
-
-
Save dnedrow/12fd0d73dc6a7473ed3630b8db7a726c to your computer and use it in GitHub Desktop.
bash function for comparing version numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" > "$1"; } | |
function version_eq() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1"; } | |
function version_lt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" < "$1"; } | |
RUBY_VERSION=$(/usr/bin/ruby -v | awk '{print $2}' | cut -d'p' -f1) | |
echo "ruby version is ${RUBY_VERSION}" | |
if version_lt $RUBY_VERSION 2.4.0; then | |
echo "ruby version is less than 2.4.0" | |
fi | |
if version_eq $RUBY_VERSION 2.0.0; then | |
echo "ruby version is 2.0.0" | |
fi | |
if version_eq $RUBY_VERSION 2.3.3; then | |
echo "ruby version is equal to 2.3.3" | |
fi | |
if version_gt $RUBY_VERSION 2.0.0; then | |
echo "ruby version is greater than 2.0.0" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment