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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -