Skip to content
Myr

[bash,zsh] Fix the version check for mawk (#4574)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

We have been checking the mawk version by extracting <x>, <y>, <z>, and <d> part from "mawk <x>.<y>.<z> <d>" in the output of the "mawk -W version" and testing <x>, <y>, <z>, and <d> using an arithmetic evalaution. However, <d> 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 <d> 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.

authored by Koichi Murase · committed by GitHub · parent c1b259c · Browse files · 5 files+20 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+20 added−5 removed

  • other:+20 added−5 removed

5 files+20 added−5 removed

modified:shell/common.sh+4 added-1 removed
modified:shell/completion.bash+4 added-1 removed
49 unmodified lines
50 __fzf_awk=/usr/xpg4/bin/awk51 elif command -v mawk > /dev/null 2>&1; then52 local n x y z d53 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)54 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk54 [[ $n == mawk ]] &&55 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&56 ((d >= 20230302)) 2> /dev/null &&57 __fzf_awk=mawk58 fi59 fi60 LC_ALL=C exec "$__fzf_awk" "$@"61}
632 unmodified lines
modified:shell/completion.zsh+4 added-1 removed
113 unmodified lines
114 __fzf_awk=/usr/xpg4/bin/awk115 elif command -v mawk > /dev/null 2>&1; then116 local n x y z d117 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)118 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk118 [[ $n == mawk ]] &&119 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&120 ((d >= 20230302)) 2> /dev/null &&121 __fzf_awk=mawk122 fi123 fi124 LC_ALL=C exec "$__fzf_awk" "$@"125}
350 unmodified lines
modified:shell/key-bindings.bash+4 added-1 removed
36 unmodified lines
37 __fzf_awk=/usr/xpg4/bin/awk38 elif command -v mawk > /dev/null 2>&1; then39 local n x y z d40 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)41 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk41 [[ $n == mawk ]] &&42 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&43 ((d >= 20230302)) 2> /dev/null &&44 __fzf_awk=mawk45 fi46 fi47 LC_ALL=C exec "$__fzf_awk" "$@"48}
126 unmodified lines
modified:shell/key-bindings.zsh+4 added-1 removed
56 unmodified lines
57 __fzf_awk=/usr/xpg4/bin/awk58 elif command -v mawk > /dev/null 2>&1; then59 local n x y z d60 IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null)61 [[ $n == mawk ]] && ((d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004)) && __fzf_awk=mawk61 [[ $n == mawk ]] &&62 (((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null &&63 ((d >= 20230302)) 2> /dev/null &&64 __fzf_awk=mawk65 fi66 fi67 LC_ALL=C exec "$__fzf_awk" "$@"68}
103 unmodified lines