×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
0
Language: Bash
Posted by: Gerrit Viljoen
Added: Sep 30, 2014 9:57 AM
Modified: Oct 10, 2014 8:23 AM
Views: 34
Make bash commands exit when they throw an error.

http://www.davidpashley.com/articles/writing-robust-shell-scripts/#id2382181
http://stelfox.net/blog/2013/11/fail-fast-in-bash-scripts/
  1. error_handler() {
  2.     echo "Error at line ${1} returned ${2}"
  3. }
  4. trap 'error_handler ${LINENO} $?' ERR
  5. set -o nounset
  6. set -o errexit
  7. set -o pipefail
  8.