From 5cb695744fb9e418585065f1aca110cc2d901ca3 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 31 Oct 2025 21:14:41 +0900 Subject: [PATCH] [bash,zsh] Fix the version check for mawk (#4574) We have been checking the mawk version by extracting , , , and part from "mawk .. " in the output of the "mawk -W version" and testing , , , and using an arithmetic evalaution. However, is ensured to be an integer only in "x.y.z >= 1.3.4". Otherwise, it may cause a syntax error in the arithmetic evaluation. The mawk started to include the date as an integer in the position only from mawk-1.3.3-20090721. We should first check that "x.y.z >= 1.3.4" and then check the value of "d". In case, "mawk -W version" produces a completely different text, we should also redirect stderr of the arithmetic commands to /dev/null. --- shell/common.sh | 5 ++++- shell/completion.bash | 5 ++++- shell/completion.zsh | 5 ++++- shell/key-bindings.bash | 5 ++++- shell/key-bindings.zsh | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/shell/common.sh b/shell/common.sh index 758f5958..6bd35f2e 100644 --- a/shell/common.sh +++ b/shell/common.sh @@ -26,7 +26,10 @@ __fzf_exec_awk() { # version >= 1.3.4 local n x y z d IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) - [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk + [[ $n == mawk ]] && + (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null && + ((d >= 20230302)) 2> /dev/null && + __fzf_awk=mawk fi fi # Note: macOS awk has a quirk that it stops processing at all when it sees diff --git a/shell/completion.bash b/shell/completion.bash index c30c47bf..7f399839 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -51,7 +51,10 @@ __fzf_exec_awk() { elif command -v mawk > /dev/null 2>&1; then local n x y z d IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) - [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk + [[ $n == mawk ]] && + (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null && + ((d >= 20230302)) 2> /dev/null && + __fzf_awk=mawk fi fi LC_ALL=C exec "$__fzf_awk" "$@" diff --git a/shell/completion.zsh b/shell/completion.zsh index bcd5829d..c90a7fc2 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -115,7 +115,10 @@ __fzf_exec_awk() { elif command -v mawk > /dev/null 2>&1; then local n x y z d IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) - [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk + [[ $n == mawk ]] && + (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null && + ((d >= 20230302)) 2> /dev/null && + __fzf_awk=mawk fi fi LC_ALL=C exec "$__fzf_awk" "$@" diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index 30b776a5..130ae936 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -38,7 +38,10 @@ __fzf_exec_awk() { elif command -v mawk > /dev/null 2>&1; then local n x y z d IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) - [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk + [[ $n == mawk ]] && + (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null && + ((d >= 20230302)) 2> /dev/null && + __fzf_awk=mawk fi fi LC_ALL=C exec "$__fzf_awk" "$@" diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index 36c03499..565529fd 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -58,7 +58,10 @@ __fzf_exec_awk() { elif command -v mawk > /dev/null 2>&1; then local n x y z d IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) - [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk + [[ $n == mawk ]] && + (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null && + ((d >= 20230302)) 2> /dev/null && + __fzf_awk=mawk fi fi LC_ALL=C exec "$__fzf_awk" "$@"