Is there a way to show multiple elements from an array and how to show all of them using a variable for the index, for example:
Here I can get the elements :
ANIMALS=('DOG' 'CAT' 'CAW' 'BIRD')
INDEX=1
echo ${ANIMALS[$INDEX]}
CAT
INDEX=2
echo ${ANIMALS[$INDEX]}
CAW
Question 1, how can I get all elements using the variable index? I'm assigning it the value @, but I'm getting the following error:
INDEX=@
echo ${ANIMALS[$INDEX]}
-bash: @: syntax error: operand expected (error token is "@")
Expected Resutl: show all the elements in the array
Question 2, How can I show multiple elements , for example if I want to show elements in the index 0 and 3, something like:
INDEX="0 3"
echo ${ANIMALS[$INDEX]}
Expected result:
DOG BIRD