Skip to content
FLAVIO COPES
flaviocopes.com
2026

How to loop over an array in Bash

By Flavio Copes

Learn how to loop over an array in Bash using a for loop and the ${list[@]} syntax to iterate over every element and echo each one in turn.

~~~

I had an array of 3 strings:

list=( "first" "second" "third" )

and I wanted to loop over them in a bash shell script.

Here’s how I did it:

for i in "${list[@]}"
do
   : 
   echo $i
done
Tagged: CLI · All topics
~~~

Related posts about cli: