Skip to main content
deleted 58 characters in body
Source Link

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

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

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 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

added 59 characters in body
Source Link

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

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 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

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

added 351 characters in body
Source Link

If gaps are a problem, then you can make a new array with just 32 lines:

arr=(pluto pippo toby)  unset arr[0]arr[1] #1ª line Below are the values, newArr=$(echo​​and $their indices without continuity: for i in "${!arr[@]})"; do arr=() 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 $newArr${arr[@]})" #2ª line 

Then, the output will be:

   Then, the output will be: for i in "${!arr[@]}"; do printf '${arr[%s]}=%s\n' "$i" "${arr[$i]}" done ${AR[0]}=pippo ${AR[1]}=toby  

Output: ${AR[0]}=pluto ${AR[1]}=toby

Indices: 0 and 1

If gaps are a problem, then you can make a new array with just 3 lines:

arr=(pluto pippo toby) unset arr[0] newArr=$(echo ${arr[@]}) arr=() IFS=' ' read -ra arr <<< "$(echo $newArr)" 

Then, the output will be:

 for i in "${!arr[@]}"; do printf '${arr[%s]}=%s\n' "$i" "${arr[$i]}" done ${AR[0]}=pippo ${AR[1]}=toby  

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    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

added 16 characters in body
Source Link
Loading
Source Link
Loading