Loops and Lists
For Loops
Accumulating Values
A for loop runs the same body for each word in a list. Accumulators update one step at a time.
Program
Play the script to see n visit three values and total grow.
for_loop.sh
#!/usr/bin/env bash
total=0
for n in 2 4 6; do
total=$((total + n))
done
echo "$total"
for loop
`for name in list` assigns one word at a time and runs the body.
accumulator
An accumulator stores a running result across loop iterations.