Syntax

Bash Arithmetic Syntax

In Bash, arithmetic: does integer math — total=$(( a + b ))

Quick Answer

Syntax
total=$(( a + b ))
BashSyntax

Arithmetic

Code example
total=$(( a + b ))

Does integer math.

Learn More

How to arithmetic in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash Arithmetic Syntax

Use total=$(( a + b )).

Related Syntax References

Frequently asked questions

What is the Bash syntax for arithmetic?

Use this pattern: total=$(( a + b ))

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify