Skip to content

Commit 8c136ed

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

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
@@ -1367,8 +1367,11 @@ _comp_finalize()
13671367
fi
13681368
fi
13691369

1370-
unset -v '_comp_finalize__depth[-1]'
1371-
unset -v '_comp_finalize__target[-1]'
1370+
# Note: bash 4.2 does not support negative array indices with `unset`
1371+
# like `unset -v 'arr[-1]'` even when the array has at least one
1372+
# element. It is supported in bash 4.3.
1373+
unset -v '_comp_finalize__depth[${#_comp_finalize__depth[@]}-1]'
1374+
unset -v '_comp_finalize__target[${#_comp_finalize__target[@]}-1]'
13721375
if ((${#_comp_finalize__depth[@]} == 0)); then
13731376
eval -- "${_comp_finalize__original_return_trap:-trap - RETURN}"
13741377
_comp_finalize__original_return_trap=

0 commit comments

Comments
 (0)