Test for a substring without double brackets
Test for a substring in POSIX sh with case $s in *sub*) instead of [[ ]]. Quote the variable inside the pattern, or its glob characters are matched as patterns.
The script runs under /bin/sh, which has no [[ $s == *sub* ]], and you need to know whether one string contains another.
s="hello world"
sub=wor
case $s in
*"$sub"*) echo "contains $sub" ;;
*) echo "no $sub" ;;
esac
sub='l*o'
case $s in
*"$sub"*) echo "quoted: matched" ;;
*) echo "quoted: no match" ;;
esac
case $s in
*$sub*) echo "unquoted: matched" ;;
*) echo "unquoted: no match" ;;
esaccontains wor
quoted: no match
unquoted: matchedA case pattern is a shell glob, and a star on each side turns it into a contains test. It is part of the POSIX shell grammar, so it runs in dash, busybox and every other sh. Quoting the variable inside the pattern makes its value literal, which is why the quoted test looks for the three characters l, star and o and fails, while the unquoted one treats the star as a wildcard.
The test is case sensitive, and a pattern cannot be a regular expression. If the substring may hold glob characters and you want them literal, quote it every time. For anything beyond contains, starts with and ends with, use grep -q or move the script to Bash.