Created
January 25, 2021 04:18
-
-
Save lvjian700/015b3cc9befca4591901df507289f032 to your computer and use it in GitHub Desktop.
Debugging 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
#!/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