On Thu, May 01, 2025 at 08:46:59 -0400, Chet Ramey wrote:
> You can already remove portions of strings with word expansion operators,
> and it's fairly easy to write a function to, say, remove the last element
> of an indexed array.
I'm not saying that anything needs to be changed, but it's actually a
bit of a pain in the butt to remove the last element of an indexed
array, because of sparseness. The problem breaks down to "find the
last index" and then an unset, and the only ways to find the last index
are to iterate over all the indices, or create a second array containing
all the indices and then find *its* last element via ${#temp[@]}.
Of course, if you know in advance that the array is non-sparse, then
it's a lot easier (use ${#array[@]} and subtract 1).