#!/bin/bash # This script is expecting to be run as: # bash -e run-me-with-e.sh # Therefore, the first failure will cause # the entire script to abort. trap die ERR die() { echo "Failed at line $BASH_LINENO" exit 1 } echo "Checking hostname..." hostname -f echo "Checking for null values..." n=`cat *.txt | grep -c "null" || /bin/true` if [ "$n" -eq "0" ]; then echo "No null values found." else echo "FATAL: Found $n null value(s)": grep null *.txt echo "Fix these before continuing." exit 1 fi echo "Finished."