This tutorials explains about comparing two numbers for equal or not in bash and shell programming
How to Check two numbers are equal or not in Bash
This program takes input values checks if two values are same or not.
first=13
second=15
if (( first == second )); then
echo "Two numbers are equal";
fi
Some shell scripts does 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 if fi
conditional statement
first=13
second=15
if [ "$first" -eq "$second" ]; then
echo "Two numbers are equal";
fi
You can also do with ternary operator
first=13
second=15
echo $(( first == second ? "equal": "not equal" ))