Bash 'for' loop syntax?

2019-04-04 17:01发布

What is the syntax for a Bash for loop?

I have tried:

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

I get this error:

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

3条回答
Explosion°爆炸
2楼-- · 2019-04-04 17:07

Replace

for (($i=0...

with

for ((i=0;i<10;i++))
查看更多
狗以群分
3楼-- · 2019-04-04 17:28

Another way

for i in {0..9}
  do
    echo $i
  done
查看更多
乱世女痞
4楼-- · 2019-04-04 17:34

The portable way is:

for i in `seq 0 9`
do
    echo "the i is $i"
done
查看更多
登录 后发表回答