$ arr=(1 2 3)
$ arr+=(4)
$ echo ${arr[@]}
1 2 3 4
Since Bash uses sparse arrays, you shouldn’t use the element count ${#arr} as an index. You can however, get an array of indices like this:
$ indices=(${!arr[@]})
$ arr=(1 2 3)
$ arr+=(4)
$ echo ${arr[@]}
1 2 3 4
Since Bash uses sparse arrays, you shouldn’t use the element count ${#arr} as an index. You can however, get an array of indices like this:
$ indices=(${!arr[@]})