#! /bin/sh

# This version of readloop prints a message if the word (arg1) was found in 
# the file (arg2), if the word could not be found in the file, or if the file
# could not be opened.

# Read two words from a line
echo "Enter a word and a file name to look in:"
read arg1 arg2

# Keep going until $arg1 doesn't contain anthing 

while [ ! -z "$arg1"  ]  
do
    echo "Looking for \"$arg1\" in file $arg2:"
    grep $arg1 $arg2 > /dev/null 2>&1
    exit_code=$?
    echo $exit_code

    if [ $exit_code -eq 0 ]
    then
	echo "Found \"$arg1\" in $arg2"

    elif [ $exit_code -eq 1 ]
    then
	echo "\"$arg1\" does not appear in $arg2"

    else 
       #[ $exit_code -eq 2 ]

	echo "Could not read $arg2"
    fi
    echo --------------------
    echo

    echo "Enter a word and a file name to look in:"
    read arg1 arg2

done
