Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi ...i am presenting creating a phone book..i go the menu running already but i dont know how to link the subprogrames to the menu....is it like this?
echo" 1) display a telephone number"
echo" 2) add a new number"
read selection
case $selection in
"1")
echo"u wan ot dispaly a number"
displaynumber----> my file to display a number..
"2")
echo "u wan to to add a new number"
addnewNmber
esac...pls correct if i am wrong..this is onli part of my script....asap..thanx!!

#!/bin/sh
display_number() {
echo 'Enter number: \c'
read number
if [ "$number" ] ; then
grep "$number" myphonebook
fi
}echo 'Enter selection: \c'
read selectioncase $selection in
1) echo "u wan ot dispaly a number"
display_number ;;
(more case statement)
esacThe above code shows subroutine display_number and shows it being called from a case statement. Each section of case statement must be terminated with a double semicolon. Getting a selection from the user and the case statement to process it needs to be in a looping structure such as a while statement.
Some statements will produce an error if a variable is null. For example:
if [ $number = 999 ]
would get evaluated by the shell as:
if [ = 999 ]
when $number is null, which of course it could be if entered by a user. To guard against this, enclose in double-quotes:
if [ "$number" ]
My subroutine is just doing a grep because I do not know the format of myphonebook. A simple grep will not suffice because that will search entire line for the string, and it might find other occurrences that you do not want, such as in someone's address. When you know the exact format of your phone book, you can code a more discriminating statement.

![]() |
SCO disk cloning
|
No Shell
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |