How to check if a string contains a substring in Bash

How to check if a string contains a substring in Bash

In this post we will give you information about How to check if a string contains a substring in Bash. Hear we will give you detail about How to check if a string contains a substring in BashAnd how to use it also give you demo for it if it is necessary.

This below example will show you, how to check if a string contains a substring in the bash script.

str="How are you"if [[ $str = *you* ]]; then  echo "it's found"fi#output--> it's found

In the above code, we have used wild card character * to find a substring in the given str.

If your substring contains spaces you need to add double quotes with the * character.

str="How are you"if [[ $str = *"are you"* ]]; then  echo "it's found"fi# output--> it's found

Hope this code and post will helped you for implement How to check if a string contains a substring in Bash. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US