Skip to content

Commit 91c5f9d

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

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
@@ -934,8 +934,11 @@ _comp_finalize()
934934
fi
935935
fi
936936

937-
unset -v '_comp_finalize__depth[-1]'
938-
unset -v '_comp_finalize__target[-1]'
937+
# Note: bash 4.2 does not support negative array indices with `unset`
938+
# like `unset -v 'arr[-1]'` even when the array has at least one
939+
# element. It is supported in bash 4.3.
940+
unset -v '_comp_finalize__depth[${#_comp_finalize__depth[@]}-1]'
941+
unset -v '_comp_finalize__target[${#_comp_finalize__target[@]}-1]'
939942
if ((${#_comp_finalize__depth[@]} == 0)); then
940943
eval -- "${_comp_finalize__original_return_trap:-trap - RETURN}"
941944
_comp_finalize__original_return_trap=

0 commit comments

Comments
 (0)