Prepare calculations and chart results with Bash Math, Shell Style

Tutorials – Shell Math

Article from Issue 223/2019

While Bash is not the most advanced environment for doing and visualizing math, its power will surprise you. Learn how to calculate and display your results with shell scripts.

In this series' previous installments on Bash scripting [1, 2, 3, 4], I have explained how to use data structures, flow control commands, and testing operators. Now, I will show you how to handle number-related tasks with shell scripts.

Before getting started, I want to discuss the strengths and weaknesses of doing math inside shell scripts.

Bash cannot do floating-point math or plotting. As for speed, fast calculations of any kind have never been a selling point of Unix shells. When it comes to performance, there have been many, much better solutions since before C and Fortran. Today, with the right libraries, even other scripting languages are better choices if raw execution speed is your main requirement.


Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Tutorial – Shell Scripting

    You do not need to learn low-level programming languages to become a real Linux power user. Shell scripting is all you need.

  • Tutorials – Shell Scripts

    Letting your scripts ask complex questions and give user feedback makes them more effective.

  • Bash scripting

    A few scripting tricks will help you save time by automating common tasks.

  • Binary Data in Bash

    Bash is known for admin utilities and text manipulation tools, but the venerable command shell included with most Linux systems also has some powerful commands for manipulating binary data.

  • Bash vs. Vista PowerShell

    Microsoft’s new PowerShell relies on .NET framework libraries and thus has access to a treasure trove of functions and objects. How does PowerShell measure up to traditional shells like Bash?

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95