=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE DICA UNIX
Dica Unix 2669 - 24 de abril de 2007 http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
COMPARAÇÃO ARITMÉTICA
Em um shell do Unix há uma limitação, pois o mesmo só consegue fazer comparações de valores inteiros. Aqui está uma dica para conseguir comparar sem problemas valores em ponto flutuante nos comandos shell : ——— CORTE AQUI —————–
#! /bin/sh
test shell script
n1=“01.401” n2=“01.350” function compareFloatSmall { sort -n <<: | head -1 $n1 $n2 : }
function compareFloatGreat { sort -r -n <<: | head -1 $n1 $n2 : }
small=$(compareFloatSmall $n1 $n2) echo “Comparing $n1 to $n2: smaller $less” great=$(compareFloatGreat $n1 $n2) echo “Comparing $n1 to $n2: greater $great”
——— CORTE AQUI —————–
Alternatively you can use a small ‘awk’ program.
——— CORTE AGORA AQUI ———–
#! /bin/sh
A couple of examples in awk.
n1=“03.550” n2=“02.550” echo “$n1 $n2” | awk ‘{ if ( $1 >= $2 ) print $1 if ( $1 <= $2 ) print $2 if ( $1 > $2 ) print $1 if ( $1 < $2 ) print $2 if ( $1 == $2 ) print $1, $2 }’
——— CORTE AGORA AQUI ———–
Esta dica foi generosamente remetida por : sthackeray@netscape.net
Para assinar: http://www.ugu.com/sui/ugu/show?tip.subscribe Para sair: http://www.ugu.com/sui/ugu/show?tip.unsubscribe Para enviar uma dica: http://www.ugu.com/sui/ugu/show?tip.today
=============================================== DECLARAÇÃO: TODAS AS DICAS DE UNIX SÃO PROPIEDADE DA UNIX GURU UNIVERSE E NÃO SÃO PARA SER VENDIDAS, IMPRESSAS OU USADAS SEM O CONSENTIMENTO POR ESCRITO DA UNIX GURU UNIVERSE. TODAS AS DICAS SÃO “USADAS POR SEU PROPIO RISCO”. UGU ADVERTE PARA TESTAR TODAS AS DICAS EM UM AMBIENTE QUE NÃO ESTEJA EM PRODUÇÃO.
Unix Guru Universe - www.ugu.com - tips@ugu.com - Copyright 1994-2007 =========================================================================