Q:

Why doesn't division produce a result in shell programming?

I have a shell programe, a little part of it can be seen as following:
count=1000
total=100000
percent=`expr $count/$total`

it cannot produce the division result, in the result file, only 1000/100000 was shown.
Any help? Many thanks.~

A:

You need to add spaces before and after '/' sign:
percent=`expr $count / $total`

But it's an integer division. So you either need to multiply $count by 100 first or use something like 'bc'.

A:

You should have spaces between values to be divided and / operator like here:
count=1000
total=100000
percent=`expr $count / $total`
#                   ^ ^ - those are important

A:

better use bc:
percent=$(echo "scale=2; $count/$total" | bc)

