So, Let's say i have an array arr, with two element in it:
read -a arr <<< "$@"
where i would then either use it in a function or script and input two string or element like so:
read_me() {
read -a arr <<< "$@"
}
read_me "first test"
Now i already know how to get through all the elements of an array:
for i in "${arr[@]}"
do
echo "$i" # where i do something with the respective element of said array.
done
But that only do it using the normal/original order in which the element were added to the previously mentioned array... Of course, i also know how to get the elements of an array in reverse order:
indices=( ${!arr[@]} )
for ((i=${#indices[@]} - 1; i >= 0; i--)) ; do
echo "${arr[indices[i]]}"
done
Both of these ways work as intended. Problem though, is that i need both the normal and the reverse order on the same loop. Mostly so i wouldn't need to do this:
echo "${arr[0]}" "${arr[1]}"
echo "${arr[1]}" "${arr[0]}"
How could i do this in a single loop?