![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| exiting from script | arghya_owen | Shell Programming and Scripting | 1 | 06-02-2008 06:36 AM |
| error occurs while some users login | rrlog | HP-UX | 0 | 08-12-2007 04:55 PM |
| Script Not Exiting??? | lesstjm | Shell Programming and Scripting | 1 | 07-11-2007 11:58 AM |
| PHP5 Script 'Freeze' before exiting | Unbeliever | Shell Programming and Scripting | 4 | 05-10-2007 11:32 AM |
| Shell script not exiting Gracefully | smithK | Shell Programming and Scripting | 5 | 02-08-2007 06:48 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Exiting from script when error occurs
Hi Friends,
Is it possible to exit nicely(ie, to echo a message with the error occurred) from a shell script(quiet a big one ) once it encounter an error in between the lines?For example, in my script I am calling the command mkdir and sometimes (when the directory already exists) it fails.then i want my script to exit with the error message.Currently it passes to the next command. I tried using the below function at the start of the script: Code:
#!/bin/sh
check_errs()
{
if [ "${1}" -ne "0" ]; then
echo "ERROR # ${1} : ${2}"
exit ${1}
fi
}
#main script
mkdir newdir_$sid
check_errs $?
Can any one give me pointers on how to call this function after every command executed or someother method by which i can exit from program as soon as an error occurs... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|