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.
This will make the script terminate on any unhandled error.
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.