mercredi 29 avril 2015

Comparing float values in bash

Hi I would like to compare 2 float numbers in bash but I haven't find anything that works properly. My actual code is the following:

  if [ $(echo " 0.5 > $X " | bc -l )==1 ]
  echo grande
  fi
  if [ "$(bc <<< "$X - 0.5")" > 0 ] ; then
  echo 'Yeah!'
  fi

What happens is that no matter if the X is bigger or smaller than 0.5, it always echos both sentences and I don't know why. I know the X is bigger or smaller than 0.5 because I also echo it and I can see it.

Aucun commentaire:

Enregistrer un commentaire