Skip to content

Commit

Permalink
fix(iperf): work around failglob with backslash in bash-5.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akinomyoga committed Nov 28, 2023
1 parent 835be1c commit 979f04f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions completions/iperf
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,21 @@ _comp_cmd_iperf()
[[ $was_split ]] && return

# Filter mode specific options
local i filter=cat
local -a filter=(cat)
local i
for i in "${words[@]}"; do
case $i in
-s | --server)
filter='command sed -e /^Client.specific/,/^\(Server.specific.*\)\?$/d'
filter=(command sed -e '/^Client.specific/,/^\(Server.specific.*\)\?$/d')
;;
-c | --client)
filter='command sed -e /^Server.specific/,/^\(Client.specific.*\)\?$/d'
filter=(command sed -e '/^Server.specific/,/^\(Client.specific.*\)\?$/d')
;;
esac
done
[[ $filter != cat ]] && filter+=' -e /--client/d -e /--server/d'
[[ $filter != cat ]] && filter+=(-e '/--client/d' -e '/--server/d')

_comp_compgen_help - <<<"$("$1" --help 2>&1 | $filter)"
_comp_compgen_help - <<<"$("$1" --help 2>&1 | "${filter[@]}")"
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
} &&
complete -F _comp_cmd_iperf iperf iperf3
Expand Down

0 comments on commit 979f04f

Please sign in to comment.