Substring matching in Bash
Let's say we have the following two strings:
string = ”Cased is the modern engineering enablement platform”
substring = ”Cased”
If we want to check if
substring we can use the following expression to do so.
This will evaluate to true and print “Search string contains substring” if
substring. Otherwise, it will evaluate to false and print “Search string does not contain substring”.
This expression utilizes Bash's built-in conditional operator
== surrounded by the
[[ ]] wildcards. These wildcards are used for pattern matching. Specifically, the
* wildcard represents zero or more characters while the
represents a range of characters.
For instance, if you wanted to check if the string starts with or ends with a particular substring it would look like this: