If gaps are a problem, then you can make a new array with just 2 lines:
arr=(pluto pippo toby) unset arr[1] #1ª line Below are the values, and their indices without continuity: for i in "${!arr[@]}"; do printf '${arr[%s]}=%s\n' "$i" "${arr[$i]}" >> borramepen; done Output: ${arr[0]}=pluto ${arr[2]}=toby
Indices: 0 and 2
To recover the continuity of the indices, it is necessary to do: IFS=' ' read -ra arr <<< "$(echo ${arr[@]})" #2ª line (or readarray -d' ' arr <<< "$(echo ${arr[@]})") Then, the output will be: for i in "${!arr[@]}"; do printf '${arr[%s]}=%s\n' "$i" "${arr[$i]}" done Output: ${AR[0]}=pluto ${AR[1]}=toby
Indices: 0 and 1