How to do arithmetic in bash

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2024-11-23

How to do math in Unix command line?

Best way is $(( 2 + 2 ))- note the double parentheses.

This is better than expr, which is outdated.