#! /bin/sh

# This version of readloop prints a message for each of the words (arg2) that
# was found in the file (arg1), 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 file name and a list of words to look for:"
read arg1 arg2

# Keep going until $arg1 doesn't contain anthing 

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

	if [ $exit_code -eq 0 ]
	then
	    echo "Found \"$word\" in $arg1"
	    
	elif [ $exit_code -eq 1 ]
	then
	    echo "\"$word\" does not appear in $arg1"

	else 
	#[ $exit_code -eq 2 ]
	
	    echo "Could not read $arg1"
	    break
	fi
	echo --------------------
	echo
	shift
    done

    echo "Enter a file name and a list of words to look for:"
    read arg1 arg2

done
