Bash shell scripts
dial

#--------------------------------------------------------------------------
# Script:	dial
# Author: 	Duncan Potter, EUCS, June 1997
#
# Phonebook search script using grep filter operations
# Operation:
# dial  
#
# "keyword" is an optional parameter to narrow down the search
#--------------------------------------------------------------------------

clear
if 
	[ "$#" = 2 ]
then
	echo Searching Phone directory for $1 with GREP filter $2;echo " "
	phones -S $1 | grep -i $2 | more
	out=$(phones -S $1 | grep -i $2)
elif
	[ "$1" = /? ]	#User is requesting help, advise them of usage.
then
	echo "Usage of this command is";echo "   dial  ";echo
	exit
elif 
	[ "$#" = 1 ] 	#Only one input parameter, the name to be searched for.
then
	echo Searching Phone directory for $1 ... 
	phones -S $1 | more
	out=$(phones -S $1 | more)
else
	echo "Correct usage of this command is";echo "   dial  ";echo
	exit
fi


# Test for the "no matches" scenario and advise user.
if
	[ "$out" = "" ]	#Null string, nothing was found.
then
	echo;echo "Sorry, no matches found with your GREP parameter."
	echo "Trying search without it ... ";echo
	phones -S $1 | more
fi

exit