1
0 Comments

When enclosed in double parentheses, Incrementing a variable like (( var++ )) it works in bash.  However, I have found that it fails if the variable is set to 0 before like var=0.

$ a=0
$ ((a++)) && echo "command succeeded" || echo "command failed"
command failed

$ a=1
$ ((a++)) && echo "command succeeded" || echo "command failed"
command succeeded

Can anyone explain to me why this happens?

I am using gnome-terminal on Ubuntu Desktop 18.04.5 LTS.

Askify Moderator Edited question April 15, 2023