return value of ((a++)) in shell

Viewed 1584

I got an unexpected behavior of a shell script. Finally I found that the error is caused by the return code of ((a++)). but I don't know why. The simplified script is as followed:

set -e
a=0
((a++))
echo "here"

The output of the script above is empty.

then I remove the set -e and print the return code of ((a++)) then the script becomes

 a=0
((a++))
echo $?
echo $a
echo "here"

then the output is

1
1
here

then I call ((a++)) one more time:

a=0
((a++))
echo $?
echo $a
((a++))
echo $?
echo $a
echo "here"

the output is:

1
1
0
2
here

So why is the return code of ((a++)) different when I call it two times?

Thanks very much!

0 Answers
Related