![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX and Linux Applications Questions involving software not covered by other forum go here. This includes Databases and Middleware. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to detect failure from batch SFTP and SHELL operations | chengwei | Shell Programming and Scripting | 2 | 05-28-2008 04:32 AM |
| copy command failure | mynix | Shell Programming and Scripting | 1 | 12-15-2007 08:35 PM |
| find command to detect installations | goldenglobe | UNIX for Dummies Questions & Answers | 2 | 06-13-2007 07:06 AM |
| Automatically executing a command | robbiegregg | UNIX for Dummies Questions & Answers | 8 | 04-06-2005 08:46 AM |
| failure of at command | DKuester | UNIX for Dummies Questions & Answers | 5 | 10-10-2003 09:58 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
How to automatically detect command failure
I have a shell script. In this script I executes various command and my requirement is such that if any command fails I've to terminate the shell script.
To achieve this objective I'm checking the value of $? after each command and if its value is greater thaen I 'exit' the script. Is there any way through which I can avoid the if condition on $? after each and every command as It a pain to put if condition after every command. |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
set -e It's more picky than you think, so a script which was not written to cope with this probably has unchecked commands which might bite you in the back. (It's good for the self-discipline, of course.) For example, anything like hello && echo success will terminate the script if hello fails. You need to rewrite that as an if ... then, or artificially add || true at the end. |
|||
| Google UNIX.COM |