Operating System - HP-UX
1838689 Members
4120 Online
110128 Solutions
New Discussion

Re: Return command in a shell script

 
Chartier Jerome
Frequent Advisor

Return command in a shell script

Hello,

Is there an equivalent command for the return command in HP world. I'm trying to debug compaq scripts to work on HP, but a return command doesn't work (it's normally going back in a loop and do some tests).

Thanks in advance

Regards

J??r??me
J@Y
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: Return command in a shell script

I don't understand your question. HP's POSIX and Korn shells have the return command and it works as advertised. Normally it is used to return a function result but if used while not in a function then it is equivalent to an exit.

What may be happening is that you are using a return in a sourced script
e.g.

. myscript.sh
within a parent script. In this case, the sourced script becomes part of the parent process and a return is then an exit.
If it ain't broke, I can fix that.
Marco Santerre
Honored Contributor

Re: Return command in a shell script

Hi Jerome,

If you put a return code after your exit statement at the end of your code, you should be able to get that return code you are looking for.

Cooperation is doing with a smile what you have to do anyhow.
Julio Yamawaki
Esteemed Contributor

Re: Return command in a shell script

If you want to test return code in shell script, you can do:

exit n ==> n is the number

To test:

if [[ $? = n ]]
then
...
fi

This test can be done by other shell script.