Skip to content

Instantly share code, notes, and snippets.

@sunkencity
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunkencity/a69488e0b630d48fa287 to your computer and use it in GitHub Desktop.
Save sunkencity/a69488e0b630d48fa287 to your computer and use it in GitHub Desktop.
exit on error in shellscript
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