Bash checking if string does not contain other string

I have a string ${testmystring} in my .sh script and I want to check if this string does not contain another string.

    if [[ ${testmystring} doesNotContain *"c0"* ]];then
        # testmystring does not contain c0
    fi 

How can I do that, i.e. what is doesNotContain supposed to be?


ANSWERS:


Use !=.

if [[ ${testmystring} != *"c0"* ]];then
    # testmystring does not contain c0
fi

See help [[ for more information.


As mainframer said, you can use grep, but i would use exit status for testing, try this:

#!/bin/bash
# Test if anotherstring is contained in teststring
teststring="put you string here"
anothersting="sting"

echo ${teststing} | grep --quiet "${anothersting}"
# Exit status 0 means anotherstring was found
# Exit status 1 means anotherstring was not found

if [ $? = 1 ]
then
  echo "another string was not found"
fi


 MORE:


 ? Comparison of 2 string variables in shell script
 ? Comparison of 2 string variables in shell script
 ? Comparison of 2 string variables in shell script
 ? Comparison of 2 string variables in shell script
 ? difference between sh and bash when symlink is used
 ? Get files in bash script that contain an underscore
 ? Bash function to find all Git commits in which a file (whose name matches a regex) has *changed*
 ? check two conditions in if statement in bash
 ? Check for substring using unix make
 ? String contains in Bash that is a directory path