string='My long string' if [[ $string == *"My long"* ]]; then echo "It's there!" fi
NOTE: Spaces in the Substring need to be placed between double quotes.
The * asterisks should be outside the double quotes.
A simple comparison operator is used (i.e. ==), not the regex operator =~.
The comparison can be reversed by just switching to != in the test.
string='My string'; if [[ $string =~ "My" ]]; then echo "It's there!" fi
case "$string" in *foo*) # Do stuff ;; esac