Question about function

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about function
# 1  
Old 11-07-2002


Last edited by jy2728; 11-13-2002 at 08:53 AM..
# 2  
Old 11-07-2002
I corrected some of your errors and it at least will run now...

echo "Welcome To My Phone Book.\n\n"
sleep 2

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;;

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

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

function select3
	echo"You only need to Make this once..\n"
    	echo "" >> phone1.log

function close
	echo "Exiting..\n"
    	sleep 1

# we can invoke a function only after we defined it.

# 3  
Old 11-07-2002
I will diff compare the above two posts to learn quickly what Perderabo had done!!

# 4  
Old 11-07-2002
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.
# 5  
Old 11-07-2002
remove the loop construct if you don't want the circle...

while : ; do


# 6  
Old 11-07-2002
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?


# 7  
Old 11-07-2002
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about sorting -- how to pass an array to a function

Hi, guys I just wanted to sort the elements of an array ascendingly. I know the following code does work well: array=(13 435 8 23 100) for i in {0..4} do j=$((i+1)) while ] do if } -le ${array} ]] then : else min=${array} ${array}=${array} ${array}=$min fi... (5 Replies)
Discussion started by: franksunnn
5 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Perl Question - split function with csv file

Hi all, I have a csv file that appears as follows: ,2013/03/26,2012/12/26,4,1,"2017/09/26,5.75%","2017/09/26,1,2018/09/26,1,2019/09/26,1,2020/09/26,1,2021/09/26,1",,,2012/12/26,now when i use the split function like this: my @f = split/,/; the split function will split the data that is... (2 Replies)
Discussion started by: WongSifu
2 Replies

3. Programming

question about function object

I have a code as following: #include <iostream> #include <algorithm> #include <list> using namespace std; //the class Nth is a predicates class Nth{ private: int nth; int count; public: Nth(int n):nth(n),count(0){} bool operator()(int){ ... (2 Replies)
Discussion started by: homeboy
2 Replies

4. Programming

question about Function pointers

Hello forum memebers As iam new to C++ programming i am little bit confuse to understand the function pointers. Please help me to understand the function pointers with examples are suggest me good site for this,Its better if it have picturial representation ie any PPTS available in Google.... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

5. Shell Programming and Scripting

Question about Function calls

Hello everyone, here's my problem: I want to create two shell scripts. one of them should includes some functions, the other one just the function calls. Is this possible? Can i call a function which is placed in a scriptfile eg out of another script eg :confused: And if... (2 Replies)
Discussion started by: Sebi0815
2 Replies

6. Shell Programming and Scripting

A question about the PID of a background function

Dear all, I'm writing a KornShell script that calls inside it a function in background mode #!/bin/ksh function myfunction { . . .} myfunction |& . . . How can I capture the PID of the function myfunction that runs in background? Thanks in advance :) (2 Replies)
Discussion started by: dariyoosh
2 Replies

7. Programming

Question about the system() function in C

Hello all ! Could someone throw some light on whether there's a limit to the number of characters contained in the command string that is passed to the system() call in C. Is it OS dependent? If yes, what are the limits for each? Thanks. (4 Replies)
Discussion started by: vsanjit
4 Replies

8. Shell Programming and Scripting

Question for calling oracle function from perl

Dear Sir/Madam, I use the following way to call the oracle stored procedure in a perl script, but I do not know how to call a oracle function by the following way ? # ARGV is the oracle stored procedure name with parameters $str = "sqlplus -s <<-eof \n" . "$db_login... (0 Replies)
Discussion started by: ili
0 Replies

9. UNIX for Dummies Questions & Answers

Date function question

hi guys! just want to ask if you could help me with the sript i'm working on. i need to automatically generate a summarized report everyday for all transactions the day before and ftp it to another machine. my only problem is that i need to name the file as the date yesterday. for example if i... (12 Replies)
Discussion started by: crpalermo
12 Replies

10. Programming

sco unix 5.0.5 call sytem() function question!please help me!

i want to know the return value of calling system function in the sco unix 5.0.5.what is the meaning of the return value? ............ int ret; char cmd; strcpy(cmd,"compress -F -c file >file.Z"); ret = system(cmd); ............. i want to know how to judge whether the file's compress is... (4 Replies)
Discussion started by: hit
4 Replies
Login or Register to Ask a Question