-
-
Save ljharb/6e70a79ac5fcf11a8b9de654a88642aa to your computer and use it in GitHub Desktop.
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
nvm_version_greater() { | |
command awk 'BEGIN { | |
if (ARGV[1] == "" || ARGV[2] == "") exit(1) | |
split(ARGV[1], a, /\./); | |
split(ARGV[2], b, /\./); | |
for (i=1; i<=3; i++) { | |
if (a[i] && a[i] !~ /^[0-9]+$/) exit(2); | |
if (b[i] && b[i] !~ /^[0-9]+$/) { exit(0); } | |
if (a[i] < b[i]) exit(3); | |
else if (a[i] > b[i]) exit(0); | |
} | |
exit(4) | |
}' "${1#v}" "${2#v}" | |
} | |
set -e | |
if nvm_version_greater 0.12.0 0.12.87; then echo y; else echo n; fi |
Turns out it's a bug in bash 3.2, fixed in 4.4: bats-core/bats-core#72 (comment) and https://tiswww.case.edu/php/chet/bash/CHANGES
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bash/sh on my mac exits with 3; zsh and dash properly echo 'n'. Any idea what's going on?