PBOOK

#!/bin/sh
# This is a simple phone book script that is easy to understand and
# uses a bunch of basic shell script commands and statements. 
# pbook stores names and numbers in a file called dlist.               
# pbook is also available with comments

lookup()
{
clear 

echo ""
echo ""
echo ""
echo " Select phone number by First or Last name."
echo " If proper spelling is not known, first several letters will match all"
echo " occurrences.                     (Interrupt to abort) "
echo ""
echo "Please Enter Name >>>\c"
read NAME 


if [ ! -f /u/doug/bin/dlist ]; then
    echo "You must have some phone numbers in you pbook before you can look"
    echo "one up!"
    sleep 2
    clear
    break
fi

if [ -z "$NAME" ]; then
    echo "You didn't enter a name!"
    echo "Please Enter Name >>>\c"
    read NAME
fi
    grep -i "$NAME" /u/doug/bin/dlist  2> /dev/null

case "$?" in
    1) echo "Name not in phone listing.";;
    2) echo "You didn't enter a name to search for" ;sleep 2; lookup;;
esac

}

addmore()
{

clear

echo ""
echo ""
echo ""
echo "            Enter information to be stored in phone list."
echo "                       (Interrupt Aborts)"
echo ">>\c"
read NEWNAME 

echo "$NEWNAME" >> /u/doug/bin/dlist
sort -o /u/doug/bin/dlist /u/doug/bin/dlist

}
clear

while true 
do
    echo ""
    echo ""
    echo "			PBOOK PHONE LIST"
    echo ""
    echo ""
    echo ""
    echo "		0. exit program"
    echo "		1. select phone number"  
    echo "		2. add name and phone number"
    echo "		3. display dlist"
    echo "		4. edit dlist (vi editor)"
    echo ""
    echo "Enter Option >>>\c"
        
 
read ANS
case $ANS in 
	0 ) clear; exit;;
	1 ) lookup;;            
	2 ) addmore; clear;;
	3 ) more /u/doug/bin/dlist ;clear;;
	4 ) vi /u/doug/bin/dlist ; clear;;
        * ) echo "INVALID CHOICE!"; sleep 2; clear;;
esac
done

Back to Unix Page

Back to Doug's home page.