Last active
January 11, 2024 22:14
-
-
Save dserodio/f7ea2d05e521bc1f092f7fa9ec354bd3 to your computer and use it in GitHub Desktop.
Template for creating shell scripts in Bash
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
#!/bin/bash | |
# "Bash strict mode" (see http://redsymbol.net/articles/unofficial-bash-strict-mode/) | |
set -euo pipefail | |
IFS=$'\n\t' | |
# Improved "strict mode" (see https://olivergondza.github.io/2019/10/01/bash-strict-mode.html) | |
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
debug() { | |
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2 | |
} | |
# Useful helper functions (from https://github.com/hashicorp/tfc-getting-started/blob/main/scripts/setup.sh) | |
info() { | |
printf "\r\033[00;35m$1\033[0m\n" | |
} | |
success() { | |
printf "\r\033[00;32m$1\033[0m\n" | |
} | |
fail() { | |
printf "\r\033[0;31m$1\033[0m\n" | |
} | |
divider() { | |
printf "\r\033[0;1m========================================================================\033[0m\n" | |
} | |
pause_for_confirmation() { | |
read -rsp $'Press any key to continue (ctrl-c to quit):\n' -n1 key | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment