Just another WordPress.com site

Linux BASH – Comparison Operators

 Integer Comparison Operators

Operator Description Example
-eq Is Equal To if [ $1 -eq 200 ]
-ne Is Not Equal To if [ $1 -ne 1 ]
-gt Is Greater Than if [ $1 -gt 15 ]
-ge Is Greater Than Or Equal To if [ $1 -ge 10 ]
-lt Is Less Than if [ $1 -lt 5 ]
-le Is Less Than Or Equal To if [ $1 -le 0 ]
== Is Equal To if (( $1 == $2 )) [Note: Used within double parentheses]
!= Is Not Equal To if (( $1 != $2 ))
< Is Less Than if (( $1 < $2 ))
<= Is Less Than Or Equal To if (( $1 <= $2 ))
> Is Greater Than if (( $1 > $2 ))
>= Is Greater Than Or Equal To if (( $1 >= $2 ))


 String Comparison Operators

Operator Description Example
= or == Is Equal To if [ “$1” == “$2” ]
!= Is Not Equal To if [ “$1” != “$2” ]
> Is Greater Than (ASCII comparison) if [ “$1” > “$2” ]
>= Is Greater Than Or Equal To if [ “$1” >= “$2” ]
< Is Less Than if [ “$1” < “$2” ]
<= Is Less Than Or Equal To if [ “$1” <= “$2” ]
-n Is Not Null if [ -n “$1” ]
-z Is Null (Zero Length String) if [ -z “$1”]


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: