From 6dc2c1df9a484cf01e7f48e25a1e36e328c32816 Mon Sep 17 00:00:00 2001 From: louib <3301383+louib@users.noreply.github.com> Date: Tue, 28 Jul 2020 06:12:43 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bash=20version=20check=20(?= =?UTF-8?q?#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bash version check was performed before declaring the emoji array, so an error message was displayed by bash before printing the custom error message. I also changed the exit code to 1 (error) in the case of an old bash version. --- emojify | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/emojify b/emojify index 5743626..4b70480 100755 --- a/emojify +++ b/emojify @@ -22,6 +22,15 @@ emojify_version=2.1.0 +version_error_message="Oh my! That’s a very old version of bash you’re using, we don’t support that anymore :( +Consider upgrading it or, if you must use bash ${BASH_VERSION}, download an old version of +emojify from here: https://github.com/mrowa44/emojify/blob/old_bash_support/emojify" +# Checks the installed bash version to see if it's compatible with emojify +if (( ${BASH_VERSION%%.*} < 4 )); then + echo -e "$version_error_message" + exit 1 +fi + # List generated by # https://gist.github.com/GrenderG/fd4eb4c73eadad219b0ecb5f9345070a#file-emoji_scrap-py # and emoji_scrap_github.py @@ -2860,18 +2869,6 @@ EOF exit 0 } -# Checks the installed bash version to see if it's compatible with emojify -check_version () { - if (( ${BASH_VERSION%%.*} >= 4 )); then - return - else - echo -e "Oh my! That’s a very old version of bash you’re using, we don’t support that anymore :(\n" \ - "\nConsider upgrading it or, if you must use bash ${BASH_VERSION} download an old version of" \ - "emojify from here: https://github.com/mrowa44/emojify/blob/old_bash_support/emojify" - exit 0 - fi -} - # If arguments are provided on the command line then check for supported help # options or process the arguments as emoji names. if [[ -n $1 ]]; then @@ -2889,12 +2886,10 @@ if [[ -n $1 ]]; then ;; * ) - check_version emojify_line "$*" ;; esac else - check_version while IFS=''; read -r line || [ -n "$line" ]; do emojify_line "$line" done