LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2011, 09:29 AM   #1
Gfaith31
LQ Newbie
 
Registered: Jul 2011
Posts: 1

Rep: Reputation: Disabled
Smile 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
 
Old 07-23-2011, 11:34 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
First, use code tags to post code.

Quote:
Originally Posted by Gfaith31 View Post
$fnum >> PHONEBOOK;
This is wrong. You're running the command stored in "$fnum" and appending its output to the PHONEBOOK file. I assume you want to append the contents of the "$fnum" variable to the file. This is how:

Code:
echo "$fnum" >> PHONEBOOK
if [ yn == "y" -o yn == "Y" ]
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" ]
then
    sed '0, $fdel' PHONEBOOK;
else
    createmenu
fi
Finally, it looks like this is homework. Are you using bash, or just plain sh? If you're using bash, it has a lot of great syntax to make your script simpler and more readable.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Making myself known here. iamdickens LinuxQuestions.org Member Intro 2 01-09-2009 04:01 PM
LDAP Phonebook zevatron Linux - Software 3 09-09-2007 02:47 AM
Mobile phonebook synchronization software? B407 Linux - Software 6 03-10-2007 07:16 AM
How to trasnsfer phonebook from PC to phone kcarun Debian 4 02-09-2007 11:32 PM
Want to read phonebook from LG TP5200 cell phone bmcneely0 Linux - Newbie 0 12-20-2003 08:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration