Skip to content

Instantly share code, notes, and snippets.

@mattolenik
Created August 29, 2019 19:29
Show Gist options
  • Save mattolenik/a4eeeb9291f7274576e321365d769986 to your computer and use it in GitHub Desktop.
Save mattolenik/a4eeeb9291f7274576e321365d769986 to your computer and use it in GitHub Desktop.
bash function for ensuring bash version meets a certain minimum
# Ensures the shell meets some minimum version, useful when using bash features introduced after a certain release
check_version() {
local reqMajor="$1"
local reqMinor="$2"
local major minor
IFS=. read -r major minor _ <<< "$BASH_VERSION"
if (( major < reqMajor )) || (( major == reqMajor && minor < reqMinor)); then
echo "Bash version $reqMajor.$reqMinor or greater required, found $major.$minor" >&2
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment