Bash 'for' loop syntax?

前端 未结 3 1429
面向向阳花
面向向阳花 2021-02-19 23:45

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:

相关标签:
3条回答
  • 2021-02-20 00:23

    Another way

    for i in {0..9}
      do
        echo $i
      done
    
    0 讨论(0)
  • 2021-02-20 00:28

    Replace

    for (($i=0...
    

    with

    for ((i=0;i<10;i++))
    
    0 讨论(0)
  • 2021-02-20 00:41

    The portable way is:

    for i in `seq 0 9`
    do
        echo "the i is $i"
    done
    
    0 讨论(0)
提交回复
热议问题