bash script if compare strings code example
Example 1: bash scripting string comparison
#!/bin/bash
VAR1="Linuxize"
VAR2="Linuxize"
if [ "$VAR1" = "$VAR2" ]; then
echo "Strings are equal."
else
echo "Strings are not equal."
fi
Example 2: number compare in bash
#!/bin/bash
# Script to do numeric comparisons
var1=10
var2=20
if [ $var2 -gt $var1 ]
then
echo "$var2 is greater than $var1"
fi
# Second comparison
If [ $var1 -gt 30]
then
echo "$var is greater than 30"
else
echo "$var1 is less than 30"
fi