This tutorial explains comparing two numbers for equal or not in bash and shell programming
How to Check whether two numbers are equal or not in Bash
This program takes input values and checks if two values are the same or not.
first=13
second=15
if (( first == second )); then
echo "Two numbers are equal";
fi
Some shell scripts do not support (())
, use [[]] with Comparison operators
Following are Comparison operator
-eq: equal -ne : Not equal -lt : Less than -le : Less than equal -gt : Greater than -ge: Greater than or equal
used the -eq operator in the if fi
conditional statement
first=13
second=15
if [ "$first" -eq "$second" ]; then
echo "Two numbers are equal";
fi
You can also do it with the ternary operator
first=13
second=15
echo $(( first == second ? "equal": "not equal" ))