looping through an array with the for loop in bash

VALUES=(
value1
value2
value3
...
valueN
)

# Alternately:
#VALUES=("value1" "value2" "value3" "..." "valueN")

for ((i=0; i<${#VALUES[@]}; i++))
do
  echo ${VALUES[$i]}
done

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

bash for loop

VALUES="value1 value2 value3 ... valueN"
for i in $VALUES
do
  echo $i
done

Comment