Making a phonebook!
Nice day!
We have an ongoing assignment, the assignment should states that we'll gonna make a like-phonebook using shell scripting that allows user to add, edit, delete, view(in sorted data) and search. I already make it but it does not return sorted data and does not allow me to edit.... This is the code: PHONEBOOK="address-book.txt" createmenu() { echo "~~~~~PHONEBOOK~~~~~" echo "1.Add" echo "2.Edit" echo "3.Delete" echo "4.View" echo "5.Exit" echo "Enter your choice:" return 1 } add() { echo "~~~~~NEW CONTACT~~~~~" echo "Contact Name:" read fname echo "Enter Number:" read fnum echo "Do you want to add contact,`echo $fname`?[y/n]" read yn if [ $yn == "y" -o $yn == "Y" ] then echo $fname $fnum >> PHONEBOOK; echo "added `echo $name`"; createmenu fi exit 0 } del() { echo "~~~~~DELETE~~~~~" echo "Enter name to be deleted:" read fdel x=`grep $fdel PHONEBOOK` echo $x echo "Are you sure you want to delete?, `echo $fdel`?[y/n]" read yn if [ yn == "y" -o yn == "Y" ] then sed '0, $fdel' PHONEBOOK; else createmenu fi } view() { echo "~~~~~CONTACTS~~~~~" echo "Name Phone Number" sort -d < PHONEBOOK } exit() { if $5 then exit 1 } createmenu read choice case $choice in 1) add;read;; 2) echo "OK";read;; 3) del;read;; 4) view;; 5)exit;; *) echo "aRGH!";read; esac Hope you can help me with this. Thank you and GOD Bless |
First, use code tags to post code.
Quote:
Code:
echo "$fnum" >> PHONEBOOK then sed '0, $fdel' PHONEBOOK; else createmenu fi[/QUOTE] This is not wrong, but it's quite ugly. It's a good idea to nicely format your code to make it readable: Code:
if [ yn == "y" -o yn == "Y" ] |
All times are GMT -5. The time now is 05:28 AM. |