0

I have the following code:

TEMP1=$(awk '$12 == "beacon_server" {print}' < numbers2.log | awk -v var="$i" '{total += $var} EN    D {print total/NR}')

Almost the same for the other TEMP-variables.

Now i want to calculate the following and save it in a new variable RESULT:

RESULT=$(expr 100 - $TEMP1 - $TEMP2 - $TEMP3 - $TEMP4)

The error message is telling me that there is a non-integer argument --> expr: non-integer argument

How can I resolve this error?

manuelgr
  • 498
  • 1
  • 8
  • 26
  • Well, what are the values of each of the `TEMP` variables when you get that error? One or more of them *isn't* an integer. As an aside, prefer `RESULT=$(( 100 - $TEMP1 - $TEMP2 - $TEMP3 - $TEMP4))` to using the external command `expr`. – chepner May 23 '17 at 14:45
  • What do you mean by "binary expression" in this context? – Charles Duffy May 23 '17 at 14:46
  • @CharlesDuffy: I mean the multiple subtractions with binary expression (maybe it should be called binary expressionS) – manuelgr May 23 '17 at 14:50
  • @chepner: The TEMP variables are real numbers. If I do it without the expr as you said, I get this: `arithmetic expression: expecting EOF: " 100 - 1 - 2.23333 - 0.333333 - 0"` – manuelgr May 23 '17 at 14:54
  • @ErebosM, what binary expressions? `-` is not a binary expression, in the "bitwise" sense of the word (indeed, bitwise math doesn't generally make much sense with floating-point math). – Charles Duffy May 23 '17 at 15:01
  • 1
    @ErebosM, ...and inasmuch as you're trying to do non-integer math, the flagged duplicates are entirely apropos. – Charles Duffy May 23 '17 at 15:02

1 Answers1

1

Error message means that one of the arguments is not an integer to find which and to fix the problem you have to display variables content as the file numbers2.log is not provided we can't find the values.

echo variable

echo "TEMP1=$TEMP1"
...

Or

declare -p ${!TEMP*}

To compute floating point numbers values

exit | awk "END{ print 100 - $TEMP1 - $TEMP2 - $TEMP3 - $TEMP4 }"

or

bc -l <<<"100 - $TEMP1 - $TEMP2 - $TEMP3 - $TEMP4"
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36