0

Currently i'm writing a script that checks whether an amount is higher than the other.

if [ "324,53" -gt "325,00" ]; then
  echo "Amount is higher!"
else
  echo "Amount is lower."
fi

Obviously i'm receiving the error: "integer expression expected" when running this. I tried to use sed 's/[^0-9]*//g'` but i need the full number again for further use. Problem is that I don't know the correct way how to do this. Can anybody give some advice?

NetMonk
  • 55
  • 6

1 Answers1

1

Bash can't handle floating point numbers. You need to use an external tool, e.g. bc, but you need to use decimal point, not comma:

if (( $(bc <<< '324.53 > 325.00') )) ; then

bc prints 1 when the condition is true, and 0 when it's false. $(...) takes the output of the command, and (( ... )) interpret it as a number, returning false for zero and true for anything else.

choroba
  • 231,213
  • 25
  • 204
  • 289