Help grep one variable over other

Hi,

I am trying to grep one variable over the other variable

Example:

 
 
i=abc
j=ab
grep $j $i

I am getting this error:

The error is due to $i being variable and not file. I know I could do it by putting the value of abc in a file
and then greping it.

 
echo $i > temp.txt

But I would like to avoid creating unnecessary temp file.

Note: Depending on the return code of grep command I am planning to invoke other unix commands.

Help is appreciated to help achieve this.

Why don't you echo and then grep :

echo "$i" | grep "$j"