The expr command is the traditional approach for performing arithmetic but it is by no means the best, and has at least two major draw backs including:
• It doesn't handle decimal points
If you want to add 5.5 and 6.5 you can't do it with expr. One solution to this is the bc command:
• Every use requires the creation of a new process
Chapter 6 includes a discussion of why this can be a problem and cause shell scripts to be very slow.
An alternative to this is to use the arithemetic capabilities provided by many of the modern shells including bash. This is what is used in the add2 script mentioned in the previous chapter.
Was this article helpful?