shell脚本for循环如何表达步长?

sh/bash/dash/ksh/zsh等Shell脚本
回复
罗非鱼
帖子: 980
注册时间: 2008-04-12 12:44

shell脚本for循环如何表达步长?

#1

帖子 罗非鱼 » 2010-04-06 13:55

for循环,循环变量是i ,循环初始值1,终止值100,步长5
请问,如何写?
头像
ibear
帖子: 787
注册时间: 2006-10-19 8:43
来自: 长江口

Re: shell脚本for循环如何表达步长?

#2

帖子 ibear » 2010-04-06 14:06

for i in $(seq 1 5 100)
好好地做一个碌碌无为的人
头像
jinsaiuser
帖子: 100
注册时间: 2007-10-10 9:25

Re: shell脚本for循环如何表达步长?

#3

帖子 jinsaiuser » 2010-04-20 16:06

for((i=1;i<=100;i+=5))
jcz37489
帖子: 6
注册时间: 2010-04-19 17:07

Re: shell脚本for循环如何表达步长?

#4

帖子 jcz37489 » 2010-04-22 20:23

shell中的for循环是列举吧,可以用while写
hellounix
帖子: 2
注册时间: 2010-04-25 17:30

Re: shell脚本for循环如何表达步长?

#5

帖子 hellounix » 2010-04-25 17:49

i=1
while [ "$i" -le 100 ]; do
...
i=$(($i+5))
done
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: shell脚本for循环如何表达步长?

#6

帖子 eexpress » 2010-04-25 20:46

学3楼的吧。
● 鸣学
回复