Bash

Increment Variable in Bash

A memo on how to add +1 to the value of a variable number in the Bash language of the Linux command line.

Shou Arisaka
1 min read
Oct 2, 2025

A memo on how to add +1 to the value of a variable number in the Bash language of the Linux command line.

This doesn’t work.

var+=1
var=var+1

Because it becomes this.

$ var=1
$ var+=1
$ echo $var
11
$ var=1
$ var=var+1
$ echo $var
var+1

Do it this way.

$ var=1
$ var=$((var+2))
$ echo $var
3
$ var=$((var+2))
$ echo $var
5

Share this article

Shou Arisaka Oct 2, 2025

🔗 Copy Links