bash if equals code example
Example 1: greater than in script
-eq
is equal to
if [ "$a" -eq "$b" ]
-ne
is not equal to
if [ "$a" -ne "$b" ]
-gt
is greater than
if [ "$a" -gt "$b" ]
-ge
is greater than or equal to
if [ "$a" -ge "$b" ]
-lt
is less than
if [ "$a" -lt "$b" ]
-le
is less than or equal to
if [ "$a" -le "$b" ]
Example 2: test string equality bash
strval1="Ubuntu"
strval2="Windows"
if [ $strval1 == $strval2 ]; then
echo "Strings are equal"
else
echo "Strings are not equal"
fi
if [ $strval1 == "Ubuntu" ]; then
echo "Linux operating system"
else
echo "Windows operating system"
fi
Example 3: bash if larger than
if (( a > b )); then
...
fi
if [ "$a" -gt "$b" ]; then
...
fi
Example 4: bash compare two strings
if [ "$s1" == "$s2" ]
then
stuff
fi