parsing error in if statement

hello,

I am trying to parse an error returned by a command inside the if statement but it is just displays the full error instead and then stops.

if [ `pkginfo xxx | grep "was not found"` ]; then
echo "no such package"
else
echo "similar version found will use pkgrm"
fi

the above code just displays

please let me know how can I parse the error message returned by a command inside the if statement.

Thanks

Your back quotes just turn the output of the command into a string.

Try

pkginfo xxx | grep "was not found"

if test "$?" = "0" ; then
echo "no such package"
else
echo "similar version found will use pkgrm"
fi

A minor correction. I think part of the problem is that the message is going to stderr and not stdout. It should be

pkginfo xxx 2>&1 | grep "was not found"