实验素材:
[root@sv7 test]# ls //此目录下包含全是 .txt结尾的文件,要求所有换成 .doc结尾
1.txt 2.txt 3.txt 4.txt 5.txtvim
编写脚本
[root@sv7 test]# vim /root/25.shbash
脚本内容:
#!/bin/bash
#定义i的取值范围,只要是以$1结尾的文件都显示
#对i执行去尾的操做,并加上新的文件后缀
#ls *.$1
要用反引号引发来
for i in ls *.$1
do
mv $i ${ i%.*}.$2 &> /dev/null ide
done测试
赋予执行权限
[root@sv7 test]# chmod +x /root/25.shcode
测试脚本:
[root@sv7 test]# /root/25.sh txt doc
[root@sv7 test]# ls
1.doc 2.doc 3.doc 4.doc 5.docit