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 

read more here

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

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -