Skip to content

Commit bdf3606

Browse files
committed
fix(_comp_finalize): avoid negative indices in unset for bash 4.2
1 parent 8d4acbc commit bdf3606

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bash_completion

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,11 @@ _comp_finalize()
919919
fi
920920
fi
921921

922-
unset -v '_comp_finalize__depth[-1]'
923-
unset -v '_comp_finalize__target[-1]'
922+
# Note: bash 4.2 does not support negative array indices with `unset`
923+
# like `unset -v 'arr[-1]'` even when the array has at least one
924+
# element. It is supported in bash 4.3.
925+
unset -v '_comp_finalize__depth[${#_comp_finalize__depth[@]}-1]'
926+
unset -v '_comp_finalize__target[${#_comp_finalize__target[@]}-1]'
924927
if ((${#_comp_finalize__depth[@]} == 0)); then
925928
eval -- "${_comp_finalize__original_return_trap:-trap - RETURN}"
926929
_comp_finalize__original_return_trap=

0 commit comments

Comments
 (0)