Formato delle versioni - X.X.X.X.
Dove X - numero.
Qual è il modo migliore per confrontare due versioni?
Io uso seguente codice:Come confrontare le versioni di alcuni prodotti in unix ksh shell?
compareVersions()
{
VER_1=$1
VER_2=$2
print -R "$VER_1"| IFS=. read v1_1 v1_2 v1_3 v1_4
print -R "$VER_2"| IFS=. read v2_1 v2_2 v2_3 v2_4
RESULT="0"
if [[ "${v1_1}" -lt "${v2_1}" ]]
then
RESULT="-1"
elif [[ "${v1_1}" -gt "${v2_1}" ]]
then
RESULT="1"
elif [[ "${v1_2}" -lt "${v2_2}" ]]
then
RESULT="-1"
elif [[ "${v1_2}" -gt "${v2_2}" ]]
then
RESULT="1"
elif [[ "${v1_3}" -lt "${v2_3}" ]]
then
RESULT="-1"
elif [[ "${v1_3}" -gt "${v2_3}" ]]
then
RESULT="1"
elif [[ "${v1_4}" -lt "${v2_4}" ]]
then
RESULT="-1"
elif [[ "${v1_4}" -gt "${v2_4}" ]]
then
RESULT="1"
fi
echo "$RESULT"
}
Ma non mi piace che - è molto semplice.
Forse c'è un modo molto corretto per confrontare le versioni?
Sei sicuro che non sia ksh invece di Bash? Bash non ha il comando 'print' e non puoi reindirizzare al suo' read'. –
Sì, questo è ksh. Ho corretto i tag. –
"non puoi sondare nella sua lettura" - certo che puoi. 'printf" abc \ n "| {leggi x; printf "ha ottenuto $ x \ n"; } ' –