Expr: non-numeric argument syntax error on line 1, teletype

Hi,

I tried to look up the issue i'm experiencing, but i'm confused what's wrong with my script.

After executing the script I'm getting the following error

expr: non-numeric argument
syntax error on line 1, teletype

After some research, it seems that the problem relates to bc.
I have the following part from the script:

FREE=`df -g $i | grep files | awk '{print$1}' | tail -1`
TOTAL=`df -g $i | grep files | awk '{print$9}' | head -1`
USED=`expr $TOTAL - $FREE`
USED_PER=`echo "scale = 5; ($USED / $TOTAL)*100" | bc`
USED_PER=`printf %0.f $USED_PER`
OUTPUT=`echo $DATE "|" $i "|" $USED_PER`

and changed the above to the below, however issue is still persisting. While performing bash -x, i noticed that all values are being retrieved, but noticed that some values are negative or float.

FREE=$(df -g $i | grep files | awk '{print$1}' | tail -1)
TOTAL=$(df -g $i | grep files | awk '{print$9}' | head -1)
USED=$(expr $TOTAL - $FREE)
USED_PER=$(echo "scale = 5; ($USED / ($TOTAL))*100" | /usr/bin/bc)
USED_PER=`printf %0.f $USED_PER`
OUTPUT=`echo $DATE "|" $i "|" $USED_PER`

Can someone shed some light on what could be the problem?

expr expects that $TOTAL and $FREE would be a numeric argument. You do not check before hand that that's what they have before using it.

From man bc in my system.

There are two attributes of numbers, the length and the scale.  The length is the total number of significant decimal digits in a num-
       ber and the scale is the total number of decimal digits after the decimal point.  For example:
               .000001 has a length of 6 and scale of 6.
               1935.000 has a length of 7 and a scale of 3.

You are using old shell scripting syntax. If you had posted what OS and shell type you are using more could had been said about those.