You can select parts of the original array with ${arr[@]:index:count}
.
Select the start, insert a new element, add the end.
To insert an element after index i=5 (the fifth element)
$ array=(1 2 3 4 5 7 8 9 12 13)
$ i=5
$ arr=("${array[@]:0:i}") ### take the start of the array.
$ arr+=( 0 ) ### add a new value ( may use $((i+1)) )
$ arr+=("${array[@]:i}") ### copy the tail of the array.
$ array=("${arr[@]}") ### transfer the corrected array.
$ printf '<%s>' "${array[@]}"; echo
<1><2><3><4><5><6><7><8><9><12><13>
To process all the elements, just do a loop:
#!/bin/bash
array=(1 2 3 4 5 7 8 9 12 13)
for (( i=1;i<${#array[@]};i++)); do
if (( array[i] != i+1 ));
then arr=("${array[@]:0:i}") ### take the start of the array.
arr+=( "0" ) ### add a new value
arr+=("${array[@]:i}") ### copy the tail of the array.
# echo "head $i ${array[@]:0:i}" ### see the array.
# echo "tail $i ${array[@]:i}"
array=("${arr[@]}") ### transfer the corrected array.
fi
done
printf '<%s>' "${array[@]}"; echo
$ chmod u+x ./script.sh
$ ./script.sh
<1><2><3><4><5><0><7><8><9><10><0><0><13>