Given an array in Bash, is there a simple and efficient way to prepend numbers for each element sequentially?
Note: Adding commas bellow just to make arrays more readable!
Example, given:
my_array=(a, b, c, d, e)
Desired as result:
my_array=(1, a, 2, b, 3, c, 4, d, 5, e)
Or getting lines from a command result, where every line would be an element, have a number prepended before each item:
readarray -t my_array < <(my_command)
If there was a way to expand the array indexes along with the elements it would work for what I need, but I didn't found anything like this.
but I didn't found anything like this.Really?