Bash 'for' 循环语法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6854118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:28:18  来源:igfitidea点击:

Bash 'for' loop syntax?

bashshellscripting

提问by jman

What is the syntax for a Bash forloop?

Bashfor循环的语法是什么?

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

回答by jman

Replace

代替

for (($i=0...

with

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

回答by Micha? ?rajer

The portable way is:

便携方式是:

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

回答by Eric Fortis

Another way

其它的办法

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