To get the values, you can use the command:
ping $1 -c1 | cut -sd '/' -f5
But you still can’t compare a float to an integer, other than the problems that other users cited.
If you really want to compare the value to zero, you can do it this way:
# Salva o valor de retorno na váriavel $avg
avg=$(ping $1 -c1 | cut -sd '/' -f5)
# Converte a variável $avg para int e compara com zero
if [ ${avg%.*} -gt 0 ]; then
# retorna OK caso seja maior que zero
echo "OK"
else
# retorna NO OK caso seja igual ou menor que zero
echo "NO OK"
fi
If I understand your command, you are determining the average time of
pingfor a particular machine. (1) is not expected to be less than or equal to zero... (2) -gt makes comparison between integers (3) the quotation around the big comandi is exchanged.– JJoao