1

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

  • possible duplicate of [why is true == false in bash?](http://stackoverflow.com/questions/8579399/why-is-true-false-in-bash) – Sakthi Kumar Sep 18 '13 at 15:13

1 Answers1

8
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.

konsolebox
  • 72,135
  • 12
  • 99
  • 105