need help to compare 2 files inside a loop

Basically, I have a user input a colour into a variable, and then i echo that variable into a text file. Then I need to compare those 2 files which is easy using the diff command. The thing I can not get is how to do this inside of a loop until the variable matches the file. Also if the user enters an incorrect colour, the script needs to prompt to re-enter until the colour is correct. Case sensitive is not an issue.

EXAMPLE

cat color_names.txt

Blue
Yellow
Red
#prompt user to enter colour
read -p "Please enter a text colour: " TextColour


#Put variable into a text file
echo $TextColour > ./TextColour.txt


#Loop until the colour is correct

Here I am not sure what kind of loop to use, and I have no idea what the syntax would be. Any help would be greatly appreciated

Thanks

This might help get you started:

while read -p "enter colour: "  colour 
do 
    echo $colour; 
done

Thanks but that isnt what the problem is. I dont know how to loop it until the user enters a colour that is inside the color_names.txt file

If /tmp/colour.txt contains the list of colours that are acceptable:

while read -p "enter colour: "  colour 
do 
    if grep -q ${colour:-foo} /tmp/colour.txt
    then
       echo right
       break          # exit the loop when a colour is in the file. 
    fi
done

This is good.....although I think it would be easier using an until loop. You will have to edit this because i know its not going to be right but for example....

read -p "colour : " colour

until grep -i "$colour" "colour_names.txt"
do *something*
done

My apologies for the loop...I am just learning. I tried your while loop but it doesnt seem to want to work.....even if the colour is right, it just keeps prompting to re renter

No need to apologise -- we all started at some point.

As far as the loop not working, is it echoing "right" when the proper colour name is entered and just not breaking? I've run it under bash and it does fine for me.

As for the until loop -- what ever works for you.

Thanks for all your help. I have figured out the solution

until   echo "$TextColour" | grep -iq "^"$TextColour"$" color_names.txt
 do
  read -p "please re-try: " TextColour
done