- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- exit on a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2001 11:19 PM
07-26-2001 11:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2001 11:26 PM
07-26-2001 11:26 PM
Re: exit on a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2001 11:54 PM
07-26-2001 11:54 PM
Re: exit on a script
after executing the script exit(1) just comes back to prompt without closing the file, where as exit(2) closes the file and comes out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 12:28 AM
07-27-2001 12:28 AM
Re: exit on a script
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 02:03 AM
07-27-2001 02:03 AM
Re: exit on a script
sorry for mistake, it's actually it is exit(0) and exit(1). yu can use exit(1) at the script end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 02:32 AM
07-27-2001 02:32 AM
SolutionFirst, it is good practice to exit a script with a defined return value. If you don't, the exit value will be the return value of the last command executed, by default.
Standards define three exit values, the remainder being a user's choice:
0 => command or process completed successfully
1 => command or process failed
2 => command or process had warnings
A good example of a command following these guidelines is 'grep'. An example of a command that deviates is 'diff'. Take a look at the man pages for both to see!
Thus, even these guidelines are not hard-and-fast.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 02:48 AM
07-27-2001 02:48 AM
Re: exit on a script
in most cases you don't really need an exit statement at the end of your script. The shell process will terminate at the end of your script unless you have set "ignoreeof" option.
Exit is mostly used to exit from within your script at certain conditions: error, file not found, execute not required, .....
"Exit" or "Exit 0" is normally used to leave the script, and state that is ended normally.
Exit codes >= 1 are normally used to indicate some error has occured.
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 05:28 AM
07-27-2001 05:28 AM
Re: exit on a script
# end of script
exit 0
then the reader will be assured that the end of the file is present.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 05:43 AM
07-27-2001 05:43 AM
Re: exit on a script
I can't resist saying "AMEN!". The notation of "end
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 06:25 AM
07-27-2001 06:25 AM
Re: exit on a script
There is one more reason, when your script calls another scrip, there is a reliable means of checking the status.
e.g.
XXX=`somecommand.sh`
STAT=$?
Now $STAT is the exit status of somecommand.sh while $XXX contains its output.
This also should be extended to functions within your scripts.
somefunc()
{
FUNCSTAT=0
echo "This is somefunc output \c:"
while [ $# -ge 1 ]
do
echo "Arg ${1} \c"
shift
done
echo
return(${FUNCSTAT})
}
XXX=`somefunc 111 222`
STAT=$?
Here the same rules as above apply. Typically, you test the exit(return) status before ever doing anything with the script(function) output.
The last point is that if you do c programming the same rules apply: main() should also return a value.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2001 06:41 AM
07-27-2001 06:41 AM
Re: exit on a script
Looking over the earlier replies, it appears that ravi was not quite correct. There is no default behavior associated with exit(1) or exit(0). Simply follow the standard rule:
0 means good; anything else not so good.