求 bash 里for的例子

sh/bash/dash/ksh/zsh等Shell脚本
回复
dugufly
帖子: 6
注册时间: 2007-04-19 17:47
送出感谢: 0
接收感谢: 0

求 bash 里for的例子

#1

帖子 dugufly » 2008-02-24 13:42

在info bash 有for 的这个用法,那位大虾举个例子
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres鈥\

sions is invalid.
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
送出感谢: 0
接收感谢: 7 次
联系:

#2

帖子 BigSnake.NET » 2008-02-24 14:29

像C一样

代码: 全选

for ((i=0;i<100;i++)) 
do
echo $i
done
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京
送出感谢: 0
接收感谢: 2 次

#3

帖子 aBiNg » 2008-02-24 14:33

BigSnake.NET 写了:

代码: 全选

for i in `ls *.mp3`
do
echo $i
done
回复

回到 “Shell脚本”