Skip to content

Commit 979f04f

Browse files
committed
fix(iperf): work around failglob with backslash in bash-5.0
In Bash 5.0, a backslash in an unquoted variable expansion $var induces a pathname expansion, and the backslash is removed. In addition, the execution fails when `shopt -s failglob` is set and there are no filenames matching the pattern. The raw variable expansion $var can also be subject to unexpected word splitting with a custom IFS. One should store command words in an array or should `eval` the command stored in a scalar variable. This PR uses an array variable. Note: This Bash behavior was required by the literal interpretation of the POSIX wording. After Bash 5.0 implemented this literal interpretation, a discussion on the POSIX interpretation arose. Finally the POSIX wording was modified to match the behavior of Bash < 5.0. Then, the Bash behavior was reverted in Bash 5.1. For this reason, this behavior of the pathname expansion is only observed in Bash 5.0.
1 parent 835be1c commit 979f04f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

completions/iperf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,21 @@ _comp_cmd_iperf()
6868
[[ $was_split ]] && return
6969

7070
# Filter mode specific options
71-
local i filter=cat
71+
local -a filter=(cat)
72+
local i
7273
for i in "${words[@]}"; do
7374
case $i in
7475
-s | --server)
75-
filter='command sed -e /^Client.specific/,/^\(Server.specific.*\)\?$/d'
76+
filter=(command sed -e '/^Client.specific/,/^\(Server.specific.*\)\?$/d')
7677
;;
7778
-c | --client)
78-
filter='command sed -e /^Server.specific/,/^\(Client.specific.*\)\?$/d'
79+
filter=(command sed -e '/^Server.specific/,/^\(Client.specific.*\)\?$/d')
7980
;;
8081
esac
8182
done
82-
[[ $filter != cat ]] && filter+=' -e /--client/d -e /--server/d'
83+
[[ $filter != cat ]] && filter+=(-e '/--client/d' -e '/--server/d')
8384

84-
_comp_compgen_help - <<<"$("$1" --help 2>&1 | $filter)"
85+
_comp_compgen_help - <<<"$("$1" --help 2>&1 | "${filter[@]}")"
8586
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
8687
} &&
8788
complete -F _comp_cmd_iperf iperf iperf3

0 commit comments

Comments
 (0)