loading...

Bash: loops

adzubla profile image Eduardo Issao Ito ・1 min read

Different loop styles in bash:

for i in $( ls )
do
    echo $i
done
for i in $( seq 1 10 )
do
    echo $i
done
for ((i = 0 ; i < max ; i++ ))
do
    echo $i
done
i=0
while [ $i -lt 10 ]
do
    echo $i
    i=$((i+1))
done
i=20
until [ $i -lt 10 ]
do
    echo $i
    i=$((i-1))
done

Discussion

markdown guide