### 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"] |