Using math in shell scripts is one area that is often ignored by shell scripting documentation—probably because so few people actually understand the subject. Shell scripts were designed more for string-based processing, with numerical computation as a bit of an afterthought, so this should come as no surprise.
This chapter mainly covers basic integer math operations in shell scripts. More complicated math is largely beyond the ability of shell scripting in general, though you can do such math through the use of inline Perl scripts or by running the bc command. These two techniques are described in “Beyond Basic Math.”
The expr Command Also Does Math
The Easy Way: Parentheses
Other Comparisons
Beyond Basic Math
Last updated: 2008-04-08