Skip to content

Instantly share code, notes, and snippets.

@timkellogg
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timkellogg/f05878a6e48f8aeb2990 to your computer and use it in GitHub Desktop.
Save timkellogg/f05878a6e48f8aeb2990 to your computer and use it in GitHub Desktop.
#!/bin/bash
function main {
`echo clear`
echo "Phonebooks on record:"
`echo find ~ -type f -name \*.dat`
echo ""
echo "Please select which phonebook"
echo "you would like to modify."
echo "Or you can create a newfile"
echo "by typing in the path"
echo "and the name of the file"
printf "with the .dat extension\n>"
read phonebook_name
menu
}
function menu {
`echo clear`
echo "Phonebook: $phonebook_name."
echo ""
echo "Select 1, 2, 3 or 4."
echo "========================="
echo ""
echo "1) add an entry"
echo "2) delete an entry"
echo "3) list file or entry"
echo "4) change entry"
echo "5) exit system"
echo "6) switch phonebook"
echo ""
echo "========================="
printf "What is your choice?\n>"
read choice
if [ $choice = 1 ]
then
addEntry
elif [ $choice = 2 ]
then
deleteEntry
elif [ $choice = 3 ]
then
listEntry
elif [ $choice = 4 ]
then
changeEntry
elif [ $choice = 5 ]
then
endProgram
elif [ $choice = 6 ]
then
main
else
echo "I'm sorry, I'm afraid I can't do that."
menu
fi
}
function addEntry {
printf "Enter a name to add\n>"
read contact_name
printf "Enter a phone number to add\n>"
read phone_number
echo "The added entry would be $contact_name: $phone_number."
`echo $contact_name: $phone_number >> $phonebook_name`
printf "Would you like to add another? [y/n]\n>"
read add_another
if [ $add_another = "y" ] || [ $add_another = 'Y' ]
then
addEntry
elif [ $add_another = 'yes' ] || [ $add_another = 'YES' ]
then
addEntry
elif [ $add_another = 'n' ] || [ $add_another = 'N' ]
then
menu
elif [ $add_another = 'no' ] || [ $add_another = 'NO' ]
then
menu
else
echo "Uh, I think that means you don't want to"
endProgram
fi
}
function deleteEntry {
printf "Enter name to delete\n>"
read name_to_delete
# return line that equals name
# if there are two matches, then have them select which one
}
function listEntry {
echo ""
echo "1) list entry"
echo "2) list file"
echo "3) back"
echo ""
printf ">"
read what_to_list
if [ $what_to_list = 1 ]
then
`echo cat $phonebook_name`
listEntry
elif [ $what_to_list = 2 ]
then
printf "What name do you want to search for?\n>"
read which_entry
`echo grep '$which_entry' $phonebook_name`
grep 'Tim' phonesys.dat
elif [ $what_to_list = 3 ]
then
menu
else
echo "Didn't understand that! Enter 1, 2 or 3"
listEntry
fi
}
function changeEntry {
printf "Enter a name or a number that you want to edit\n>"
read what_to_change
# search file for phrase
# allow ability to edit
# pipe back to .dat file
}
function endProgram {
`echo clear`
echo "Goodbye!"
exit 0
}
main
@timkellogg
Copy link
Author

In process of building

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment