From 08e8bbe3fd4a9fea7e14af5cbe0c528ab1bfbf9c Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 28 Apr 2020 09:27:56 +0200 Subject: [PATCH] Check Bash version and fail gracefully if it's not set This closes #55. --- bashtop | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bashtop b/bashtop index 373fd39..b023b28 100755 --- a/bashtop +++ b/bashtop @@ -32,6 +32,21 @@ declare -x LC_MESSAGES="C" LC_NUMERIC="C" LC_ALL="" shopt -qu failglob nullglob shopt -qs extglob globasciiranges globstar +#* Fail if Bash version is below 4.4 +bash_version_major="$(echo $BASH_VERSION | cut -d "." -f 1)" +bash_version_minor="$(echo $BASH_VERSION | cut -d "." -f 2)" +if [[ "$bash_version_major" -lt 4 ]]; then + echo "ERROR: Bash 4.4 or later is required (you are using Bash $bash_version_major.$bash_version_minor)." + echo " Consider upgrading your distribution to get a more recent Bash version." + exit 1 +else + if [[ "$bash_version_major" == 4 && "$bash_version_minor" -lt 4 ]]; then + echo "ERROR: Bash 4.4 or later is required (you are using Bash $bash_version_major.$bash_version_minor)." + echo " Consider upgrading your distribution to get a more recent Bash version." + exit 1 + fi +fi + declare -a banner banner_colors banner=(