User Tools

Site Tools


2018numeric_cmp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
2018numeric_cmp [2018/09/07 13:16]
david [Correct Numeric Comparisons]
2018numeric_cmp [2018/09/07 14:01]
david [Correct Numeric Comparisons]
Line 11: Line 11:
 You must use the flag operators, or the symbolic operators inside double parentheses,​ to correctly compare values numerically. You must use the flag operators, or the symbolic operators inside double parentheses,​ to correctly compare values numerically.
 For example, say ''​a=2''​ and ''​b=10'': ​ For example, say ''​a=2''​ and ''​b=10'': ​
-  * <​nowiki>​[ ​$a -lt $b ]</​nowiki>​ is TRUE +  * <​nowiki>​[ ​-lt 10 ]</​nowiki>​ is TRUE 
-  * <​nowiki>​[[ ​$a -lt $b ]]</​nowiki>​ is TRUE +  * <​nowiki>​[[ ​-lt 10 ]]</​nowiki>​ is TRUE 
-  * <​nowiki>​[[ ​$a -ge $b ]]</​nowiki>​ is FALSE +  * <​nowiki>​[[ ​-ge 10 ]]</​nowiki>​ is FALSE 
-  * <​nowiki>​(( ​$a $b ))</​nowiki>​ is TRUE+  * <​nowiki>​(( ​10 ))</​nowiki>​ is TRUE
  
 ===== Incorrect Numeric Comparisons (lexicographic order) ===== ===== Incorrect Numeric Comparisons (lexicographic order) =====
Line 48: Line 48:
 | ''<​nowiki>​(( 10 -lt 2 ))</​nowiki>''​ | FALSE | ''<​nowiki>​((:​ 10 -lt 2 : syntax error (error token is "2 "​)</​nowiki>''​ | | ''<​nowiki>​(( 10 -lt 2 ))</​nowiki>''​ | FALSE | ''<​nowiki>​((:​ 10 -lt 2 : syntax error (error token is "2 "​)</​nowiki>''​ |
  
-These script is:+This script is:
  
 <code bash> <code bash>
2018numeric_cmp.txt · Last modified: 2018/09/07 14:02 by david