OR logical operator in bash -
i have dumb problem can't wrap head around it
if [[ false || false ]] ; echo 'true' else echo 'false' fi
as per http://tldp.org/ldp/abs/html/comparison-ops.html
-o logical or
exp1 -o exp2 returns true if either exp1 or exp2 true.
these similar bash comparison operators && , ||, used within double brackets. [[ condition1 && condition2 ]]
so if both false should return false? why prints 'true'?
you should run not part of conditional command '[[ ]]':
if false || false; echo 'true' else echo 'false' fi
as testing falses within [[ , ]]:
if [[ ! 1 || ! 1 ]]; echo 'true' else echo 'false' fi
noting [[ false ]] equivalent [[ -n false ]] makes true condition.
if make more apparent , valid conditional test (( )) this:
if (( 0 || 0 )); echo 'true' else echo 'false' fi
Comments
Post a Comment