0

I have a bash script and in it a if statement that I can't get to work:

1 #!/bin/bash
2
3 echo "Please provide expenses for time period specified: "
4 read expenses
5
6 rev_pa=$(psql -U postgres -d crewdb -t -c "SELECT SUM(price) FROM work WHERE date_linkid BETWEEN 100 AND 500;")
7
8 blah=$(echo "$rev_pa-$expenses" | bc)
9
10 if [ "$blah" -lt 0 ]
11 
12 then
13        echo "Total expenses of $expenses exceeds total revenue of $rev_pa for the specified time period."
14
15 fi

I used expenses = 10000 and rev_pa = 12208.20 was the database output. The error message I get is:

./bash.txt: line 10: [: 12208.20: integer expression expected

Does anyone know how I can get this if statement to work in bash? Thanks for your help.

Christian Hick
  • 401
  • 3
  • 10

1 Answers1

0

12208.00 is not integer value. -lt (and others) in test must be integers.

nutilius
  • 32
  • 5
  • The OP *knows* their value isn't an integer -- that's why they put "non-integer" in the question title. – Charles Duffy Mar 10 '20 at 22:56
  • Also, see the "Answer Well-Asked Questions" section of [How to Answer](https://stackoverflow.com/help/how-to-answer), including the bullet point regarding questions that "have been asked and answered many times before". – Charles Duffy Mar 10 '20 at 22:56