Loops
for loops over lists, ranges and file patterns, and while repeats on a condition. break and continue work as in other languages.
Example
for i in 1 2 3; do
echo "i=$i"
done
for n in {1..3}; do echo -n "$n "; done
echo
count=3
while [[ $count -gt 0 ]]; do
echo "count $count"
((count--))
doneResult
i=1 i=2 i=3 1 2 3 count 3 count 2 count 1
Exercise
Start a loop.
i in 1 2 3; do echo $i; doneQuiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.