This question has two parts:
(a) Understanding what the code snipped is doing
(b) Understanding the difference between exit status and return status in context of
Here is the code snipped I am trying to understand:
if var=-2 && (( var+=2 )) then echo "True" else echo "False" fi
Running this produces
False. I cannot understand why this is happening.
If I understand this correctly here is what maybe happening with the
var=-2 creates exit status of 0, because the assignment is a success
(( var+=2 )) adds 2 to the value of
var and the expression evaluates zero. So the exit status is 1 for this term
(c) 0 && 1 creates an exist status of 0 which is then used by
if construct is supposed to simply check the exit status and when it is zero it takes the then path. In step (c) above it is zero but the script still takes the else path. Is this correct way to understand this?
Also, I keep seeing various
bash texts use exit status and return status interchangeably.
var=-2 assignment would have any kind of exit status because it is not a program. But any clarification on the difference between two will be great.