/
I corrected some of your errors and it at least will run now...
#!/bin/sh
echo "Welcome To My Phone Book.\n\n"
sleep 2
clear
function main
{
while : ; do
echo "1) Add Phone Number\n2) Add Address\n3) Make a new Phone Book.\n4) Exit\n\n"
echo "Enter: "
read choice
case $choice in
1) select1;;
2) select2;;
3) select3;;
4) close;;
esac
done
}
function select1
{
echo "Please Enter the Name: "
read Name
echo "Enter the Phone Number: "
read Number
echo "Adding To Phone Book..\n"
sleep 1
echo "Added Information.\n"
echo "==============================================\n\n" >> phone1.log
echo "Name: $Name \n" >>phone1.log
echo "Phone Number: $Number\n" >> phone1.log
echo "==============================================\n\n" >> phone1.log
sleep 2
return
}
function select2
{
echo"Please Enter the Name: "
read Name2
echo "Enter the House Number: "
read HouseNumber
echo "Enter the Phone Number: "
read PhoneNumber2
echo "Enter the Town/City: "
read TownCity
echo "+=========================================+\n" >> phone1.log
echo "Name: $Name2 \n" >> phone1.log
echo "House Number: $HouseNumber \n" >> phone1.log
echo "Phone Number: $PhoneNumber2 \n" >> phone1.log
echo "Town/City: $TownCity \n\n" >> phone1.log
echo "+=========================================+\n\n" >> phone1.log
echo "Adding Information..\n"
sleep 1
echo "Information Added.\n"
sleep 1
return
}
function select3
{
echo"You only need to Make this once..\n"
echo "" >> phone1.log
return
}
function close
{
echo "Exiting..\n"
sleep 1
exit
}
# we can invoke a function only after we defined it.
main
I will diff compare the above two posts to learn quickly what Perderabo had done!!
Cheers!
Vishnu.
The code do fix it from keep going to Select1 function but all the code do now is just going in circle in the main function no matter what you enter it just keep going back to ask for choice.
remove the loop construct if you don't want the circle...
while : ; do
done
Cheers!
Vishnu.
I took out the while loop, it stop going in circle but i still can't get to the function i wanted. eg. I type 2 in the main function it will say
: select2: not found
: function: not found
and it load the next function after the main function
does my code work on your machine, is there something worng with my unix?
Thanks
jy2728
When I run the program exactly as I posted it, it kinda works. Yes, it loops. But if I select "4" it will exit. If this is news to you, I must now wonder how much of it you actually wrote.
Without the loop, yes you only make one selection. And this this point, the option 4 to simply exit seems rather superfluous.
In either case, when I select option 2, no it doesn't work well, but it certainly finds the function called select2. But that function has at least one bug in the first statement. You need a space after the the "echo".
My guess is that you have introduced other errors. Put it back the way I posted it. It really needs that loop to make sense. Be aware that the script's author intends for you to select the "exit" option to get out. And see if you can take it from there.