topical media & game development

talk show tell print

basic-shell-03-test-num.sh / sh



  
  # Number test.
  
  echo "**** Numeric comparisons."
  x=5
  y=10
  
  echo -n "test -eq: "
  if (test x -eq y)  then
      echo "X = Y."
  else
      echo "X != Y. Expected."
  fi
  
  echo -n "test -eq: "
  if (test x -eq x)  then
      echo "X  = X. Expected."
  else
      echo "X != X. "
  fi
  
  echo -n "test -eq: "
  if (test x -eq 5)  then
      echo "X  = 5. Expected."
  else
      echo "X != 5. "
  fi
  
  echo -n "test -eq: "
  if (test x -eq "5")  then
     echo "X = \"5\". Expected."
  else
      echo "X != \"5\". "
  fi
  
  echo -n "test -ne: "
  if (test x -ne 5)  then
      echo "X != 5. "
  else    
      echo "X  = 5. Expected."
  fi
  
  echo -n "test -ne: "
  if (test x -ne y)  then   
      echo "X != Y. Expected."
  else
      echo "X = Y."
  fi
  
  # Note extra ! for "not".
  echo -n "test -ne: "
  if (test ! x -eq y)  then   
      echo "X != Y. Expected."
  else
      echo "X = Y."
  fi
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.