add

Thursday, June 21, 2012

Linux BASH - Comparison Operators


Linux BASH - Comparison Operators

 Integer Comparison Operators
OperatorDescriptionExample
-eqIs Equal Toif [ $1 -eq 200 ]
-neIs Not Equal Toif [ $1 -ne 1 ]
-gtIs Greater Thanif [ $1 -gt 15 ]
-geIs Greater Than Or Equal Toif [ $1 -ge 10 ]
-ltIs Less Thanif [ $1 -lt 5 ]
-leIs Less Than Or Equal Toif [ $1 -le 0 ]
==Is Equal Toif (( $1 == $2 )) [Note: Used within double parentheses]
!=Is Not Equal Toif (( $1 != $2 ))
<Is Less Thanif (( $1 < $2 ))
<=Is Less Than Or Equal Toif (( $1 <= $2 ))
>Is Greater Thanif (( $1 > $2 ))
>=Is Greater Than Or Equal Toif (( $1 >= $2 ))

 String Comparison Operators
OperatorDescriptionExample
= or ==Is Equal Toif [ "$1" == "$2" ]
!=Is Not Equal Toif [ "$1" != "$2" ]
>Is Greater Than (ASCII comparison)if [ "$1" > "$2" ]
>=Is Greater Than Or Equal Toif [ "$1" >= "$2" ]
<Is Less Thanif [ "$1" < "$2" ]
<=Is Less Than Or Equal Toif [ "$1" <= "$2" ]
-nIs Not Nullif [ -n "$1" ]
-zIs Null (Zero Length String)if [ -z "$1"]

No comments:

Post a Comment