bash:strings:check_if_a_string_contains_a_substring
This is an old revision of the document!
BASH - Strings - Check if a String contains a Substring
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 =~.
bash/strings/check_if_a_string_contains_a_substring.1610363855.txt.gz · Last modified: 2021/01/11 11:17 by peter