note that you have to be careful when working with floating point numbers, and if you are checking for equality, you really want to solve some kind of precision and then compare with that. Sort of:
if (abs(x1-x2) < 0.0001) then equal
the reason is that with computers we are dealing with binary fractions with limited accuracy, and not with true mathematical realities. Limiting accuracy in bc with scale = 3 will have this effect.
I would advise against trying to do this in a shell script. This does not mean that you cannot do this, but you will have to brush off many small subcommands to execute complex bits and slow execution and, as a rule, pain for writing - you spend most of your time getting the shell to do what you want rather than writing the code you really want. Instead, switch to a more complex scripting language; my language of choice is perl, but there are others. like this...
echo $var1 $var2 $total | perl -ne 'my ($var1, $var2, $tot) = split /\s+/; if ($var1/$tot == $var2/$tot) { print "equal\n"; }'
also note that you are dividing by the same value ($ total in your question), so the whole comparison can be performed against the numerators (var1 and var2) provided that $ total is positive
source share