How do I obtain the nth element in an array in a bash shell script?
-
Using syntax ${name[n]}
Define an array (Animals) and get the 5th element, remember array elements start at zero.
Animals=(lion tiger elephant gorilla hippo giraffe) Fifth_Element=${Animals[5]} echo $Fifth_Element
$ ./array.sh giraffe
© Lightnetics 2024