1

I have a problem with comparing 2 variables (one variable is read from file).

  1 #!/bin/bash
  2
  3 CFR=$(<bubble_status.txt)
  4 treshold=0.01
  5 echo $CFR
  6 echo $treshold
  7
  8 if [ "$CFR" -gt "$treshold" ]
  9 then
 10         echo "CFR is greater then treshold";
 11 elif [ "$CFR" -lt "$treshold" ]
 12 then
 13         echo "CFR is less than treshold";
 14 else
 15         echo "Something else";
 16 fi

But bash returns me this:

19.81
0.01
./dupa7.sh: line 8: [: 19.81: integer expression expected
./dupa7.sh: line 11: [: 19.81: integer expression expected
Something else

Any ideas?

0

2 Answers 2

2

Bash doesn't support float comparison. You could use bc:

if (( $(bc <<< "$CFR > $threshold") )); then
    echo "CFR is greater then threshold"
fi
Sign up to request clarification or add additional context in comments.

Comments

-1

Bash doesn't support floating point arithmetic. Use another tool such as bc or awk if you want to do floating point comparison/math.

1 Comment

comprehensive list of methods in this post stackoverflow.com/questions/8654051/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.