...

/

Increment and Decrement

Increment and Decrement

Learn how increment and decrement operations work in Bash.

The increment and decrement operations first appeared in the experimental programming language developed it in 1969 by B. Ken Thompson and Dennis Ritchie while working at Bell Labs. Dennis Ritchie later moved these operations to his new language called C. Bash later copied these behaviors from C.

Assignment operations

First, let’s consider assignment operations to help us understand how increment and decrement work. A regular assignment in arithmetic evaluation looks like this:

((var = 5))

This command assigns the number 5 to the var variable.

Bash allows you to combine an assignment with arithmetic or bitwise operation. The following command does addition and assignment at the same time:

((var += 5))

The command performs two actions:

  1. It adds the number 5 to the current value of the var variable.

  2. It ...