Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Author - MR
- #Date modified - 2/12/14
- echo "Rosales,Clifford,123456,crosales@guidon.com" > addressbook
- echo "Hizon,Joseph,654321,jhizon@batak.com" >> addressbook
- echo "Raymundo,Miguel,789012,mraymundo@gmail.com" >>addressbook
- until [ "$choice" == "4" ] #watch out for rookie mistakes
- do
- echo "======================"
- echo "What do you want to do?"
- echo "======================"
- echo "1. Add new record"
- echo "2. Display all records"
- echo "3. Search"
- echo "4. Exit"
- echo "======================"
- echo -n "Choice: "
- read choice
- echo
- # string -> "$x" == "y" --- int -> $x -eq y
- add_contact()
- {
- echo -n "Enter last name: "
- read last
- echo -n "Enter first name: "
- read first
- echo -n "Enter contact number: "
- read number
- echo -n "Enter email address: "
- read email
- echo "$last,$first,$number,$email" >> addressbook
- echo
- echo "~~~CONTACT SUCCESSFULLY ADDED~~~"
- echo
- }
- display_contacts()
- {
- cat addressbook | sed 's/,/ /g' | awk '{printf "%-15s%-15s%-15s%-15s\n",$1,$2,$3,$4}'
- echo
- }
- search()
- {
- echo -n "Entery query: "
- read query
- echo
- echo "SEARCH RESULTS:"
- echo
- cat addressbook | grep -i $query
- echo
- }
- invalid()
- {
- echo “INVALID CHOICE”
- echo
- }
- if [ $choice == "1" ]
- then
- add_contact
- elif [ $choice == "2" ]
- then
- display_contacts
- elif [ $choice == "3" ]
- then
- search
- elif [ $choice == "4" ]
- then
- echo "Auf wiedersehen"
- echo
- else
- invalid
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement