Skip to content

Instantly share code, notes, and snippets.

@ariesmcrae
Created October 24, 2024 11:21
Show Gist options
  • Save ariesmcrae/2fb287e08da60bb2c846f4d786a5c5f6 to your computer and use it in GitHub Desktop.
Save ariesmcrae/2fb287e08da60bb2c846f4d786a5c5f6 to your computer and use it in GitHub Desktop.
Bash v5 scripting: Check Bash version
usr/bin/env bash

set -euo pipefail

check_bash_version() {
    if [[ ${BASH_VERSINFO[0]} -lt 5 ]]; then
        echo "Error: At least Bash version 5 is required."
        echo "Your Bash version is: ${BASH_VERSINFO[0]}"        
        exit 1
    fi
}

function main() {
    echo "about to check bash"
    check_bash_version
    echo "bash version is ok"
    exit 0    
}

# execute main function with all command line arguments
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment