Compute Numerical Values at the Command Line

Basic Math

Article from Issue 303/2026
Author(s):

Experts use tools such as bc and dc for arithmetic in the shell. The num-utils and datamash packages open up further opportunities for processing numerical values at the command line.

Keyboard fans love working at the command line: The shell carries out your commands without any compromises. Only if you enter incorrect information does it let you know its dissatisfaction, but it even does that in an extremely courteous way.

Whether Bash, Dash, zsh, or ksh, the shell initially processes inputs as character strings, making it perfect for most tasks. When it comes to interpreting the input, the command line sometimes needs a little help since it cannot guess on its own when it needs to evaluate input as numeric. Read on to learn how to tell the shell to do this.

The use cases mostly relate to admin and statistics and often involve evaluating logfiles, say for failed login attempts, network statistics, or memory usage. Although there are specialist utilities that do this, knowing how to handle these tasks without their help is a good thing.

[...]

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

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • datamash

    A little-known, very powerful data processor for your scripts, datamash makes long, complex calculations simple.

  • Perl: Parser

    Lexers and parsers aren’t only for the long-bearded gurus. We’ll show you how you can build a parser for your own custom applications.

  • Tutorials – Shell Math

    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.

  • Tool Tips

    We test DK Tools 4.2.2, Midnight Commander 4.8.15, Datamash 1.1.0, F3 6.0, Sauvegarde 0.0.7, and WackoWiki 5.4.3.

  • LibreOffice Calc Pivot Tables

    Pivot tables let you sort, rearrange, group, and perform calculations on your spreadsheet data. We help you get started with this powerful tool.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News