O'Reilly logo

Expert Shell Scripting by Ron Peters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

PART 2System Interaction and Advanced Techniques

CHAPTER 11Math from the Shell

Mathematical calculations are an important element of writing shell scripts. In the various flavors of UNIX, there are multiple ways to perform just about any task, and mathematical tasks are no exception.

Although there are many types of mathematical computations, I've limited the discussion in this chapter to the basic operations of addition, subtraction, multiplication, and division, plus remainder, exponentiation, and trigonometric functions. The examples make use of the variables a, b, c, and d.

One note on division: some programming languages don't perform integer division like you might expect from using your traditional calculator. There are two parts to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required