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?

CC BY-SA 3.0
6
  • 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, 2017 at 14:45
  • What do you mean by "binary expression" in this context? May 23, 2017 at 14:46
  • @CharlesDuffy: I mean the multiple subtractions with binary expression (maybe it should be called binary expressionS)
    – ErebosM
    May 23, 2017 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"
    – ErebosM
    May 23, 2017 at 14:54
  • 1
    @ErebosM, ...and inasmuch as you're trying to do non-integer math, the flagged duplicates are entirely apropos. May 23, 2017 at 15:02

1 Answer 1

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"
CC BY-SA 3.0
7

Not the answer you're looking for? Browse other questions tagged or ask your own question.