User Tools

Site Tools


2018numeric_cmp

This is an old revision of the document!


Confusing comparison operators in BASH

Syntax Output Error
Numeric comparisons: “2 less than 10” should be TRUE
[ 2 < 10 ] FALSE 10: No such file or directory
[ 2 \< 10 ] FALSE
[[ 2 < 10 ]] FALSE
[[ 2 -lt 10 ]] TRUE
[ 2 -lt 10 ] TRUE
[ "2" -lt "10" ] TRUE
test 2 -lt 10 TRUE
(( 2 < 10 )) TRUE
(( 2 -lt 10 )) FALSE ((: 2 -lt 10 : syntax error (error token is "10 ")

Numeric comparisons: 10 less than 2 should be FALSE


[ 10 < 2 ] numeric_comparisons.bash: line 41: 2: No such file or directory FALSE [ 10 \< 2 ] TRUE 10 < 2 TRUE 10 -lt 2 FALSE [ 10 -lt 2 ] FALSE test 10 -lt 2 FALSE 1) FALSE 2) numeric_comparisons.bash: line 63: ((: 10 -lt 2 : syntax error in expression (error token is “2 ”) FALSE

1)
10 < 2
2)
10 -lt 2
2018numeric_cmp.1536339525.txt.gz · Last modified: 2018/09/07 10:58 by david