Цикл for

Поток управления / Циклы

#the for of C, inside (( )) the variables go without $
sum10=0
for (( i = 1; i <= 10; i++ )); do
    (( sum10 += i ))
done
#sum10 is 55

#{from..to..step} makes the list of numbers
range1=({0..4})
#range1 is (0 1 2 3 4)
range2=({0..6..2})
#range2 is (0 2 4 6)

#the braces go before the variables, so {1..$n} is not a range;
#seq takes variables, the split of its output into words is the point here
n=5
notRange=({1..$n})
#notRange is ("{1..5}")
fromSeq=($(seq 1 "$n"))
#fromSeq is (1 2 3 4 5)

echo "sum10 is $sum10"
echo "range1 is (${range1[*]})"
echo "range2 is (${range2[*]})"
echo "notRange is (${notRange[*]})"
echo "fromSeq is (${fromSeq[*]})"