In case you want to match whole words portably, first, you need to define how words are delimited. If we go for GNU grep -w's definition, then a word is a sequence of letters, numbers or underscore (and a delimiter would be any character that is not any of those). Unfortunately, the definition of "letter" is locale-dependant. POSIX shells can specify letters (with [[:alpha:]], but I don't know of any variant of the Bourne shell that does. So with a POSIX shell, you could do:
word_delimiter='[![:alnum:]_]'
case +$INPUT+ in
(*${word_delimiter}dolor${word_delimiter}*) echo true;;
(*) echo false;;
esac
And in the Bourne shell, you would have to assume US letters:
word_delimiter='[!a-zA-Z0-9_]'
case +$INPUT+ in
*${word_delimiter}dolor${word_delimiter}*) echo true;;
*) echo false;;
esac
Other options:
if
tr -cs '[:alnum:]_' '[\n*]' << EOF | grep -qx dolor
$INPUT
EOF
then
echo true
else
echo false
fi
While that syntax is POSIX, if you have to deal with as old a system as one having a Bourne shell, you may have issues with that "tr" syntax as there used to be two main variants of it in the old pre-POSIX days.
*is the globbing operator responsible for file name expansion (this way it won't work in bash either)!? Why don't you want to use otherunixstandard tools (sed, awk, perl...)? – user1146332 Sep 20 '12 at 13:43ashordash? Notbash,kshorzshrunning inshcompatibility mode? What's the actual operating system release you're using/targeting? – bahamat Sep 20 '12 at 18:22