当前位置: > shell编程 >

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

时间:2014-09-24 09:02来源:linux.it.net.cn 作者:it
使用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个文件,简单吧。

 
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容