首页 > tips > shell程序中for循环的一个小技巧

shell程序中for循环的一个小技巧

2009年12月2日 发表评论 阅读评论

在服务器上跑一些命令
经常都会用到简单的shell也算是编程
用的比较多的是for语句

for i in a b c d; do

这样的
但当in后面的列表比较长的时候
往往就不知道怎么写了
今天偶尔翻到bash的faq(?貌似是这个)
发现如果后面是一系列有规律的数字的话可以这样处理:

for i in ((i = 0; i < 10000; i++ ))

这样就行
呵呵
再联想到bash下(())括起来的可以是运算
比如echo $((3+4))
输出是7
那这种写法也就不难理解了

原创文章,转载请注明: 转载自嘻嘻哈哈的部落格(blog)

本文链接地址: shell程序中for循环的一个小技巧

分类: tips 标签: , , , ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word