DEV Community

Eduardo Issao Ito
Eduardo Issao Ito

Posted on

Bash: loops

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

Top comments (0)