Skip to content

Instantly share code, notes, and snippets.

@mickdekkers
Created November 11, 2020 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickdekkers/8dc68f12fb13bd62a408dabbe93bb813 to your computer and use it in GitHub Desktop.
Save mickdekkers/8dc68f12fb13bd62a408dabbe93bb813 to your computer and use it in GitHub Desktop.
Bash snippet to require bash version >= 4
#!/usr/bin/env bash
if [[ $BASH_VERSION == [0123].* ]]; then
>&2 printf "\033[0;31mThe %s script requires bash >= v4 (released february 2009)\033[0m\n" "$0"
>&2 echo "You are using bash $BASH_VERSION"
if [[ "$(uname -s)" == Darwin* ]]; then
>&2 echo "macOS is known to include a particularly ancient version of bash due to licensing shenanigans."
>&2 printf "You can use homebrew to update it yourself: \033[1;36mbrew install bash \033[0m\n"
fi
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment