#!/bin/bash

# Week 6 Intro to Linux Homework - Clair Dunn
# script name: minidb.sh
# lagniappe: adds a period to the initial

echo -e "\nThis script asked for full names and phone number."
echo -e "Data will be added to a file called phone_list.txt."
echo -e "Press ENTER after each entry."
echo  -e "-------------------------------------------\n"

echo -e "Enter FIRST name: --> \c"
read FNAME
echo -e "Enter Middle INITIAL if there is one, else just hit Enter: --> \c"
read MI
echo -e "Enter LAST name: --> \c"
read LNAME
echo -e "Enter PHONE number, including hyphens: --> \c"
read PHONE
#-----------------------------------------
# following if construct will add a period 
# to an initial if one is entered

if [ "$MI" = "" ]; then
	echo -e "\n$FNAME\t$MI\t$LNAME\t$PHONE\n"
else
	MIP="."
	PERIOD=$MI$MIP
	MI=$PERIOD
	echo -e "\n$FNAME\t$MI\t$LNAME\t$PHONE\n"
fi

echo -e "The above is about to be added to the database.\n If this is correct, press 'y' to accept, 'n' to abort entry:--> \c"
read ANSWER
if [ $ANSWER = "y" ]
then
	echo -e "$FNAME\t$MI\t$LNAME\t$PHONE" >> "phone_list.txt"
	echo -e "New data has been added.\n"
else
	echo -e "\nData has not been added.\n"
fi




