I must create a sequence of numbers using the number of elements that an list has.
arr1=(1 2 3 4 5 6)
I thought about the following expression in order to do so, but it is now working.
echo {0..$(expr ${#arr1[*]} - 1)}
{0..5} # output
The correct output should be:
0 1 2 3 4 5
Could anyone explain me why I do not get the correct values?
Advertisement
Answer
You just need to add an eval
:
$ a=(1 2 3 4 5 6) $ eval echo {0..$(expr ${#a[*]} - 1)} 0 1 2 3 4 5