Chapter 5. Scripting by Numbers

Number crunching was once the domain of big mainframe computers hidden away in secure, air-conditioned rooms. Now, the computer on your desk (or even the one in your pocket) has more computing power than those old behemoths. The shell, with the help of external commands, can harness that power.

POSIX shells have arithmetic built in, but are limited to integers. Multiplication of decimal fractions can be done in the shell with the fpmul function, which appears in the math-funcs library I describe next. Other operations could also be coded with shell arithmetic, but they are more complicated, and external commands such as awk can do the job as efficiently. Similarly, there is no point to using a shell function to multiply ...

Get Shell Scripting Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.