Skip to content

Instantly share code, notes, and snippets.

@brennanfee
Last active July 3, 2023 02:34
Show Gist options
  • Save brennanfee/f0c33c3f43e0c88635f46b599944048f to your computer and use it in GitHub Desktop.
Save brennanfee/f0c33c3f43e0c88635f46b599944048f to your computer and use it in GitHub Desktop.
Script Strict Modes
#!/usr/bin/env bash
# Bash strict mode
([[ -n ${ZSH_EVAL_CONTEXT:-} && ${ZSH_EVAL_CONTEXT:-} =~ :file$ ]] \
|| [[ -n ${BASH_VERSION:-} ]] && (return 0 2> /dev/null)) && SOURCED=true || SOURCED=false
if ! ${SOURCED}; then
set -o errexit # same as set -e
set -o nounset # same as set -u
set -o errtrace # same as set -E
set -o pipefail
set -o posix
#set -o xtrace # same as set -x, turn on for debugging
shopt -s inherit_errexit
shopt -s extdebug
IFS=$(printf '\n\t')
fi
# END Bash scrict mode
#!/usr/bin/env sh
# POSIX strict mode (may produce issues in sourced scenarios)
set -o errexit
set -o nounset
#set -o xtrace # same as set -x, turn on for debugging
IFS=$(printf '\n\t')
# END POSIX strict mode
SCRIPT_DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$(xdg-user-dir DOTFILES)/bash/script-tools.bash"
EXIT_CODE="0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment