Does anyone know why my bash line return 42 in code given below:
true || true && false || return 42
i am wondering why program gets to this point false || return 42
thanks for answering
Does anyone know why my bash line return 42 in code given below:
true || true && false || return 42
i am wondering why program gets to this point false || return 42
thanks for answering
true || true && false || return 42
They are simply processed in sequence:
First it starts with true
: Returns 0. $?
is set to 0.
Then next || true
: Not processed since $?
is 0 from the first true
.
Then next is && false
: Processed since $?
is still 0 from the first true
, and now false turns $?
to 1.
Then last is || return 42
: Processed since $?
is 1 from the last false
, and code returns 42.