Handling return & exit statements


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Handling return & exit statements
# 8  
Old 08-02-2010
can you tell me what value it will return by default?? after while loops finishes and comes out of the loop. Its huge code i am not sure whether it would be helpful posting here, Thank you.
# 9  
Old 08-02-2010
It will return the exit code of the last command executed (as Corona688 said earlier).

If you are testing this return value as:

Code:
function

if [ $? -eq 0 ]; then
  ....
else
  ....
fi

and the function returns a value other than zero, then the else part will be executed.

Put
Code:
set -x

at the top of your script to get some debug info.
(by top, I mean after the shebang on line 1)

Last edited by Scott; 08-02-2010 at 04:09 PM..
# 10  
Old 08-02-2010
The thing happening is after the while loops completes in script2 it is returning some nonzero value though there is no exit or return statement to return as such. I came to know from somebody that after while loop ends reading the file it has the tendency to return a random value to the script1. Which is causing issue but not sure how far is it true? Thank you.
# 11  
Old 08-02-2010
Hi.

I very much doubt it's returning a "random" value.

If you need it to return zero (and / or you don't care about the return value), do one of two things:

  • explicitly return 0 at every possible exit point in the function
  • don't test the return value back in script1

Code:
. /apps/bin/script2

function

....
....
....

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Return or exit codes apart from 0 have a meaning?

The standard return code when everything goes right is 0, but what about using any other number something happened? Are there "ranges" depending on the kind of problem you want to express or is totally up to the programmer? (3 Replies)
Discussion started by: Tribe
3 Replies

2. Shell Programming and Scripting

Need the difference between exit 1 & exit 7

Hi In one of the script I am seeing some thing like exit 7,exit 1,exit 2,exit 3,exit 9,exit6.What is the difference between all of this exit.Can anyone help here please (3 Replies)
Discussion started by: ginrkf
3 Replies

3. Shell Programming and Scripting

Problem with call of Java Programm & return code handling & output to several streams.

Hello Everybody, thanks in advance for spending some time in my problem. My problem is this: I want to call a java-Programm out of my shell skript, check if die return code is right, and split the output to the normal output and into a file. The following code doesn't work right, because in... (2 Replies)
Discussion started by: danifunny
2 Replies

4. Shell Programming and Scripting

Nested if statements with && and ||?

Hello, I'm a shell scripting noob and new to this forum as well. My question is can nested if statements be done with && and || instead and if it can be done can someone provide an example pls. Thanks in advance for the help (1 Reply)
Discussion started by: zomgshellscript
1 Replies

5. Shell Programming and Scripting

Not able to exit from case statements

Hi all, I wrote the following simple shell script to perform addition, subtraction, multiplication and division. In the below program, i am not able to exit from the script Shell Script ----------- #!/bin/sh bgcal() { cal="" echo "Enter the Option Number: \c" read cal if then... (3 Replies)
Discussion started by: uxpassion
3 Replies

6. Shell Programming and Scripting

command does not return exit status due to tee

Hi, I am using /bin/sh. I want to display the stdout and stderr on the terminal as well as save it in a file, so I'm using this command. gmake all 2>&1 | tee log But even if gmake fails, it's always giving 0 as exit status, i suppose because of tee. # false 2>&1 | tee Log # echo $? 0... (2 Replies)
Discussion started by: anand_bh
2 Replies

7. Shell Programming and Scripting

Gen. Question - Script calls multiple programs - Return Code Handling?

General Question: If a script calls multiple external programs (external to the script, but still on unix), where do the return codes go? Let's say one of external programs fails, does the entire script fail and send a non-zero return code to the job scheduling software, or is the return code sent... (1 Reply)
Discussion started by: jnanasakti
1 Replies

8. HP-UX

Return of EXIT status ( $? )

I have the question: How return the exit code from then assign : VAR=$(command ) for ex. VAR=$(ls ....) VAREXIT=$? echo $VAREXIT VAREXIT is equal to 0 if the directory exist or not exist. WHI?? if i execute the command direct from line-command , the value of $? is different if... (1 Reply)
Discussion started by: ZINGARO
1 Replies

9. UNIX for Dummies Questions & Answers

exit/return values

Sys: HP-UX 9000 In the calling script how do I 'read' the return/exit value of a called script?:confused: THX in advance for any assistence.:) (1 Reply)
Discussion started by: vslewis
1 Replies

10. UNIX for Advanced & Expert Users

Move command return with exit code of 2

I have a script which loads data files into Oracle and then moves each file into a 'processed' directory when each file has finished loading. Last night I found that the script was failing on the mv statement (with a return code 2) and the following message, mv: cannot access... (1 Reply)
Discussion started by: handak9
1 Replies
Login or Register to Ask a Question