List Manupulation in Bash

(, de)

Unset last array element

array=([1]=1 {2..5} [10]=6);
# declare -a array='([1]="1" [2]="2" [3]="3" [4]="4" [5]="5" [10]="6}")'
index=("${!array[@]}");
# declare -a index='([0]="1" [1]="2" [2]="3" [3]="4" [4]="5" [5]="10")'
unset 'array[${index[@]: -1}]';
# declare -a array='([1]="1" [2]="2" [3]="3" [4]="4" [5]="5")'

Source

# indirect expansion, not zsh
echo "last pos parameter: ${!#}"
set -- "${@: 1: $#-1}"

Source

See also