教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 bash shell循环创建多个文件的小脚本

bash shell循环创建多个文件的小脚本

发布时间:2014-10-05   编辑:jiaochengji.com
使用bash shell的循环语句创建多个文件的脚本,主要使用while与for循环,供有需要的朋友参考学习。

1、用while循环
命令:
 

复制代码 代码示例:
i=1; while [ $i -le 99 ]; do name=`printf "test%02d.txt"  $i`; touch "$name"; i=$(($i+1)); done

2、用for循环和seq命令
命令:
 

复制代码 代码示例:
for i in $(seq 99); do name=$(printf test%02d.txt $i); touch "$name"; done

以上代码均生成test01.txt到test99.txt共99个文件,简单吧。

您可能感兴趣的文章:
bash shell循环创建多个文件的小脚本
bash shell脚本执行的几种方法
python shell是什么
inux shell初级入门教程
深入解析tcsh的初始化配置文件
linux shell学习之shell流程控制
Linux Source命令解析
php与shell实现多线程的简单例子
找出1小时内占用cpu最多的10个进程的shell脚本
调试bash脚本的方法

关键词: linux shell  shell  shell循环   
[关闭]
~ ~