Bash'for'循环语法?

时间:2011-07-28 04:32:51

标签: bash shell scripting

Bash for循环的语法是什么?

我试过了:

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

我收到此错误:

line 1: ((: =0: syntax error: operand expected (error token is "=0")

3 个答案:

答案 0 :(得分:16)

替换

for (($i=0...

for ((i=0;i<10;i++))

答案 1 :(得分:11)

便携式方式是:

for i in `seq 0 9`
do
    echo "the i is $i"
done

答案 2 :(得分:7)

另一种方式

for i in {0..9}
  do
    echo $i
  done