Skip to content

Different loop in Bash

方法一

#!/bin/bash
for i in `seq 1 10`
do
    #code here
    echo $i
done

方法二

C语言风格

#!/bin/bash
for ((i=1; i<=10; i++))
do
    printf "%s\n" "$i"
done

方法三

#!/bin/bash
i=1
while [ "$i" -lt "10" ]
do
    #code here
    echo $i
    #i=$[ $i + 1 ]
    ((i++))
done