Answers for "bash if not contains string"

5

check if variable contains string bash

STRING='Hello world'
if [[ $STRING =~ "Hello" ]] ; then echo "It's here" ; fi
Posted by: Guest on April-17-2021
1

bash if substring in string

# Example usage:
FULLSTRING='Full string to search'
if [[ $FULLSTRING == *"ll str"* ]]; then
	echo "The substring 'll str' is in the full string."
fi

# Example to check for two substrings:
FULLSTRING='Full string to search'
if [[ $FULLSTRING == *"Full"* && $FULLSTRING == *"to"* ]]; then
	echo "The substrings 'Full' and 'to' are in the full string."
fi

# Note, see the following two links for why [[ ]] is used:
https://serverfault.com/questions/52034/what-is-the-difference-between-double-and-single-square-brackets-in-bash
http://mywiki.wooledge.org/BashFAQ/031
Posted by: Guest on January-17-2022

Code answers related to "bash if not contains string"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language