Doing Bash Arithmetic with Greater Precision than Integer Values

Problem scenario:  Using Bash you want to compute kB, MB, and GB with decimal values.  But you only seem to be able to do arithmetic on integer values.

Root cause:  Bash does not support "float" arithmetic with values to the right of the period.  Decimal values cannot be calculated.

Solution:  Install the bc utility/language (e.g. yum -y install bc). It is often used in Bash to augment the numeric processing features.  It is technical its own processing language, but do not be intimidated by that.

Leave a comment

Your email address will not be published. Required fields are marked *