Thread: Address book
View Single Post
  #1   (View Single Post)  
Old 5th July 2011
fossala's Avatar
fossala fossala is offline
Real Name: David
Fdisk Soldier
 
Join Date: Feb 2011
Location: Cornwall, UK
Posts: 58
Default Address book

I know there are plenty of addressbook apps that do this. It's more for learning rather than that I need it.
My code is not complete at all just started.
Code:
  1 #!/bin/sh
  2 #phonebook
  3 echo "Would you like to 'add' 'edit' or 'read' the database?"
  4 echo -n "Enter Choice: "
  5 read choice
  6         if [ $choice = add ]; then
  7                 echo -n "Please enter name for the database: "
  8                 read name
  9                 echo $name >> ~/.pbook/$name
 10                 echo "---------------------------"
 11                 echo -n "Enter Home Phone number [number/NO]: "
 12                 read -e number
 13                         if [ $number = NO ]; then
 14                                 echo ""
 15                         else
 16                                 `echo "Home number: $number" >> ~/.pbook/$name`
 17                         fi
 18                 echo -n "Enter email address [email/NO]: "
 19                 read -e eaddress
 20                         if [ $eaddress = NO ]; then
 21                                 echo ""
 22                         else
 23                                 `echo "Email address: $eaddress" >> ~/.pbook/$name`
 24                         fi
 25         elif [ $choice = read ]; then
 26                 echo -n "Please enter the clients name or list: "
 27                 read -e username
 28                         if [ $username = list ]; then
 29                                 ls ~/.pbook
 30                         else
 31                                 cat ~/.pbook/$username
 32                         fi
 33         else
 34                 echo "That is not a vailid choice"
 35         fi
What I want to is once I choose "list" under "read" it goes back to re ask me the name instead of exiting. I could do this by just adding the $username = part again but I was wondering If there was an easier/more clean way of doing this?
Reply With Quote