I'm doing a bash script and I need to get the length of an array starting from an element.
Let's say that the array is:
array=(1 2 3 4 5)
It is possible to print the array with an offset of 2 using:
echo ${array[@]:2} 3 4 5
It is possible to print the length of the array using:
echo ${#array[@]} 5
I tried printing the length of the array with an offset of 2 using:
echo ${#array[@]:2}
It doesn't work, the expected result is:
3
I have found a way to do it but I'm not sure if it's the best way:
echo $(( ${#array[@]} - 2 )) 3
Is there a best way to do this?
Thanks!