1. Home
  2. Bash
  3. Examples
  4. Check if string contains another string?

Check if string contains another string?

Brief: This example will help you to check if one string contains another substring in a bash script.

You can use wildcard character * to find if a string contains a substring in a bash script. Here is a simple example

Output:

Yes

If you have multi-word substring, use double quote around the string:

Output:

Yes

Another Example

This is another example to read a file line by line and check if a string contains a specific substring and do some operation on it. For example, check all the users in /etc/passwd having shell /bin/bash.