bash if statement
Very simple question, but it is stumping me. Could anyone explain why this if statement prints the value of $a?
Code:
a="hey" Thanks |
The if statement contains the boolean "OR" operator (||). Thus if either expression is true, then the if is true, and it goes to the echo command.
$a != "what" is true.....therefore the if is true. |
Thanks. I just didnt understand the logic behind the or. I figured that sicne the first one was false it should have stopped.
|
|| = or
&& = and |
Logical operations (and/or) are somehow confusing..
You should preferably refer to them in terms of exit status of the command not in terms of the common meaning of yes/no. In this case test exits 0 (true) , so the script continues to the further line (echo bal_bla). Ciao |
Thanks. I guess I just didnt know when the if statement exited.
|
Further, "short-cut" evaluation is used (as in C):
In an "or" condition, if the first term is true, there's no reason to evaluate the rest, and it's skipped. In an "and" condition, if the first term is false, there's no reason to evaluate the rest, and it's skipped. |
Quote:
Code:
a="hey" |
All times are GMT -5. The time now is 05:37 AM. |