Loops

C-Like (for):

for ((i = 0; i < 100; i++));
do
    echo "$i";
done

With "in" (idiomatic):

for i in <list>;
do
    echo "$i"
done

<list> kann eine "echte" Liste sein, aber auch beispielsweise ein expandierter Dateipfad, solange es durch IFS getrennte Werte sind -> bspw. /*

Range

for i in {1..5};
do
    echo "$i"
done

Noch einmal ..<step> dahinter sorgt für steps: {5..25..5} -> 5 10 15 20 25

While

x=1
while [[ $x -le 5 ]];
do
    $(( $x + 1 ))
done

Infinity

while true;
do
    echo "Forever"    
done

while :;
do
    echo "Forever"
done

Diese Loops können natürlich mit CTRL+C aufgehalten werden. Dann wird aber das gesamte Script terminiert

break und continue funktionieren in den Loops wie gewohnt

Lesen mit while

while read -r line;
do
    echo "$line"
done <file.txt