subtraction in bash arrays

hi i am using bash shell to perform some subraction. here is what i have:
i have a while loop and am using i as a counter.

diff= `expr ${ARRAY1} - ${ARRAY2}`

for example array1[1] has -0.7145 and array2[1] has -0.7041.
when i try the above command, i get expr: non-numeric argument. any ideas how i can do this subtraction?
thanks

all shell math is integer - you're dealing with floats.
Look into 'man bc'.

Try removing the space after the '=' for starters

Or try...

and see what happens...

vgersh99 makes a very good point about integer arithmetic and using bc !

Try...

Personally, I think bc is one of the worst Unix utilities around, but it has its uses!

Jerry

diff=`echo "${ARRAY1} - ${ARRAY2} | bc`

Why is that?

Having been a Unix user for 20 years, most utilities have always seemed to fit into a standard way of doing things, but bc has always seemed to me to be quirky, and I've never got really on with it. awk seemed easy to learn in comparison and I've always found alternative ways to avoid using bc.
But, I love using vi while others dislike it because, IMHO, they've never really bothered to learn to use it properly. Maybe I should take some time to properly learn bc :o

There is never any need to use expr in a bash script.

For floating-point arithmetic, you need an external command (like the shell , expr only does integer arithmetic; ksh93 is an exception).

paste <(printf "%s\n" "${ARRAY1[@]}") <(printf "%s\n" "${ARRAY2[@]}") |
awk '{ print $1 - $2 }'