Bash 'for' loop syntax?

两盒软妹~` 提交于 2019-12-21 07:29:16

问题


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")

回答1:


Replace

for (($i=0...

with

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



回答2:


The portable way is:

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



回答3:


Another way

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


来源:https://stackoverflow.com/questions/6854118/bash-for-loop-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!