$ array=(a b c d e f g h)$ array[42]="i"$ unset array[2]$ unset array[3]$ declare -p array # dump the array so we can see what it containsdeclare -a array='([0]="a" [1]="b" [4]="e" [5]="f" [6]="g" [7]="h" [42]="i")'$ echo ${#array[@]}7$ echo ${array[${#array[@]}]}h
以下是获取最后一个索引的方法:
$ end=(${!array[@]}) # put all the indices in an array$ end=${end[@]: -1} # get the last one$ echo $end42