Last active
August 29, 2015 14:02
-
-
Save sunkencity/a69488e0b630d48fa287 to your computer and use it in GitHub Desktop.
exit on error in shellscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e: Enables checking of all commands. If a command exits with an error and the | |
caller does not check such error, the script aborts immediately. Enabling this will | |
make your scripts more robust. But don't wait until your script is "complete" to set | |
the flag as an afterthought, because it will be a nightmare to fix the scrip to work | |
with this feature enabled. Just write set -e as the very first line of your code; | |
well... after the shell bang. | |
set -x: If you are writing simple scripts that are meant to, well, script the execution | |
of a few tasks (as opposed of being full-flown programs written in shell), set this | |
flag to trace the execution of all commands. This will make the interpreter print | |
each command right before it is executed, so it will aid you in knowing what is | |
happening at any point in time. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment