Categories
Linux Mastering Development

Passing arrays in to the function in bash script

I am new to a bash script and writing the bash script. I have declared an array and I have given the values. But When I pass the array in the loop values are not getting inside the loop. Below is my code

declare -a files=( "A1S0" "D1S0" "D2S0" "D3S0" "D4S0" "D5S0" "D6S0" )
command_to_get_filesizes() {
  for i in "${!files[@]}"; do
     echo Processing file "${i[${index}]}"
  done
}
command_to_get_filesizes

Expected Output

A1S0
D1s0
D2S0
D3S0
D5S0
D680

But am getting output as

Processing file 0
Processing file 1
Processing file 2
Processing file 3
Processing file 4
Processing file 5
Processing file 6

could anyone pls help me to print values in the array

Leave a Reply

Your email address will not be published. Required fields are marked *