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 ] FALSE 2: No such file or directory
[ 10 \< 2 ] TRUE
[[ 10 < 2 ]] TRUE
[[ 10 -lt 2 ]] FALSE
[ 10 -lt 2 ] FALSE
test 10 -lt 2 FALSE
(( 10 < 2 )) FALSE
(( 10 -lt 2 )) FALSE ((: 10 -lt 2 : syntax error (error token is "2 ")
2018numeric_cmp.1536339991.txt.gz · Last modified: 2018/09/07 11:06 by david