Linux shell: space in condition statement -
i learn how program in shell. can't understand why 2 statement produce different output. seems if there no spaces, test treats 10==11
string , returns true.
$test 10==11 && echo yes || echo no $yes $test 10 == 11 && echo yes || echo no $no
# single string, not null true, , result yes test 10==11 && echo yes || echo no # there exist space 10 == 11 not equal string comparison result no test 10 == 11 && echo yes || echo no
equivalents
if test 10==11; echo yes; else echo no; fi yes if test 10 == 11; echo yes; else echo no; fi no # or same above if test 10 = 11; echo yes; else echo no; fi no
from http://tldp.org/ldp/abs/html/comparison-ops.html
string comparison = equal if [ "$a" = "$b" ] caution note whitespace framing =. if [ "$a"="$b" ] not equivalent above. == equal if [ "$a" == "$b" ]
Comments
Post a Comment