Using loops in a search

Title=
echo -n "Title: "
read Title
echo -n "Author:"
read Author




validation=`grep -i "$Title" fruit | grep -i "$Author"  | awk -F":" '{ print $1}'`


if [ "$Title" = "$validation" ] ; then
clear

echo "Error! Book Already Exist"

else
echo "You may input a new book in/

hey guys, im doing a simple search program and i came up with a problem. What i am trying to achieve is, if the search is false(means the book does exist) , the program will then ask the user to input the information again(title and author) and do a search again until there is no such book and then display a message saying he can input a new book in.

i tried using a until loop, but it does not seem to work. some guidance on how the statement should be and where should it be placed?

Hello Greg,

I did use while loop & below mentioned script worked as per your requirement. I have used a variable as flag to indicate success (or) error.

#!/bin/ksh

myVal=0

validateAuthor()
{
Title=
echo -n "Title: "
read Title
echo -n "Author:"
read Author
echo ""

validation=`grep -i "$Title" fruit | grep -i "$Author"  | awk -F":" '{ print $1}'`
TITLECHECK=` echo "$Title"  | tr "[:lower:]" "[:upper:]"`
VALIDATIONCHECK=` echo "$validation"  | tr "[:lower:]" "[:upper:]"`
if [ "$TITLECHECK" = "$VALIDATIONCHECK" ] ; then
clear
echo ""
echo ""
echo "Error! Book Already Exist"
myVal=0
else
myVal=1
echo "You may input a new book in"
fi
}

while [ $myVal -eq 0 ]
do
validateAuthor
done

Regards,
B.S. Nithin.