Skip to content

Instantly share code, notes, and snippets.

@leandroh
Created March 18, 2014 11:46
Show Gist options
  • Save leandroh/9618499 to your computer and use it in GitHub Desktop.
Save leandroh/9618499 to your computer and use it in GitHub Desktop.
Comparacao de numeros decimais
#
# Comparacao de numeros decimais
# ------------------------------------------------------------
#
# Verifica se o primeiro parametro e' maior que o segundo.
#
# Exemplo simples com retorno true/false (0/1):
#
# x=1.1.2
# y=1.0.2
# echo $(compare_decimal_maior $x $y)
#
# Exemplo utilizando uma estrutura condicional de um if:
#
# if [[ $(compare_decimal_maior $x $y) -eq 0 ]]; then ... fi
#
compare_decimal_maior() {
echo $1 $2 | awk '{ if ($1 > $2) print 0; else print 1 }'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment