I've seen numerous answers to questions here and elsewhere that say you can do a grep search of a variable by echoing the variable and piping that to grep. Following the syntax of these examples, however, isn't working for me.
The following code fails, echoing "found" every time, no matter what string I'm searching for with grep
. What am I doing wrong?
TEST='This is a test of the emergency broadcast system.'
echo $TEST | grep 'blah'
if [ $? -eq 0 ]
then
echo 'not found'
else
echo 'found'
fi