'if else statement in a while command is not working... BASH

#!/bin/sh
#datafile
#script

while echo enter name
read -r code
do
if [ "$code" = 'STOP' ];
then
   break
else
grep "$code" datafile > outputres
while echo ' Would you like to see B OR R'
read -r answer
do
if [[ "$answer" = 'B'  && "$code" = datafile ]];
then
   echo show B.
   break
elif [[ "$answer" = 'R'  &&  "$code" = datafile ]];
then
   echo show R
   break
elif [[ "$answer" = 'B'  &&  "$code" != datafile ]];
then
   echo No such THING.
   break
elif [[ "$answer" = 'R' && "$code" != datafile ]];
then
   echo No such THING.
   break
else :
   echo Enter only B or R.
fi
done

fi
done
echo Goodbye!

Hello, I hope someone can help. but I'm having some issues when I execute my program I receive "no such thing" when it should display "show r".

UPDATE: I changed code to a number found in the data and it works, so I need a better way to say ("$code" = filename) number is in data or not in the data.

btw I have also checked if i have any errors and I dont



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source