Skip to content

Instantly share code, notes, and snippets.

View soliton-'s full-sized avatar

Gunter Labes soliton-

  • 14:24 (UTC +02:00)
View GitHub Profile
@soliton-
soliton- / vcompare
Last active April 19, 2021 18:22
version compare for bash
#!/bin/bash
# compare version $1 and $2; returns 0 if version $1 >= $2
# versions must be numeric only
vcompare() {
local v1=$1 v2=$2 v1a v2a n1 n2 max i
IFS=. read -ra v1a <<< "$v1"; IFS=. read -ra v2a <<< "$v2"
((n1=${#v1a[@]}, n2=${#v2a[@]}, max=(n1 > n2 ? n1 : n2)))
for ((i=0; i<max; ++i))
do