Compare Numbers and Integers in Bash

Posted on May 29, 2020 at 11:16 pm

Here is an example bash script to compare numbers:

#!/bin/bash
 
a=123456
b=123456
 
if [ "$a" -eq "$b" ]; then
  echo "Numbers are equal";
fi

Here are all comparison operators:

-eq # equal
-ne # not equal
-lt # less than
-le # less than or equal
-gt # greater than
-ge # greater than or equal

Receive updates via email

Other Posts

Updated Posts