Skip to content

Instantly share code, notes, and snippets.

@lvjian700
Created January 25, 2021 04:18
Show Gist options
  • Save lvjian700/015b3cc9befca4591901df507289f032 to your computer and use it in GitHub Desktop.
Save lvjian700/015b3cc9befca4591901df507289f032 to your computer and use it in GitHub Desktop.
Debugging shellscript
#!/usr/bin/env bash
# Enable xtrace if the DEBUG env variable is set
if [[ ${DEBUG-} =~ ^1|yes|true$ ]]; then
set -o xtrace # Trace the exec of the script(debug)
fi
# A better class of script...
set -o errexit # Exist on most errors
set -o errtrace # Make sure any error trap is inherited
set -o nounset # Disallow expansion of unset variables
set -o pipefail # Ust last non-zero exit code in a pipeline
# Colors
YELLOW_COLOR=$(tput setaf 3)
NORMAL_COLOR=$(tput sgr0)
echo "${YELLOW_COLOR}This line is yellow until ${NORMAL_COLOR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment