# Bash strings comparison Here are a few ways to compare two strings in Bash: Using the equality operator (=): ``` bash if [ "$string1" = "$string2" ]; then echo "Strings are equal" else echo "Strings are not equal" fi ``` Using the double bracket syntax: ``` bash if [[ "$string1" == "$string2" ]]; then echo "Strings are equal" else echo "Strings are not equal" fi ``` Using the inequality operator (!=): ``` bash if [ "$string1" != "$string2" ]; then echo "Strings are not equal" else echo "Strings are equal" fi ``` Case-insensitive comparison: ``` bash if [[ "${string1,,}" == "${string2,,}" ]]; then echo "Strings are equal (case-insensitive)" else echo "Strings are not equal (case-insensitive)" fi ``` Checking if one string contains another: ``` bash if [[ "$string1" == *"$string2"* ]]; then echo "string1 contains string2" else echo "string1 does not contain string2" fi ``` Key things to remember: Always quote your variables to handle spaces and special characters Use double brackets [[ ]] for more advanced comparisons The = operator works in single brackets [ ], while == is preferred in double brackets [[ ]] For POSIX compatibility, use single = even in double brackets