I found to need this functionality quite frequently, so I'm using a home-made shell function in my .bashrc
like this which allows me to reuse it as often as I need to, with an easy to remember name:
function stringinstring()
{
case "$2" in
*"$1"*)
return 0
;;
esac
return 1
}
To test if $string1
(say, abc) is contained in $string2
(say, 123abcABC) I just need to run stringinstring "$string1" "$string2"
and check for the return value, for example
stringinstring "$str1" "$str2" && echo YES || echo NO