外壳脚本目录和特定文件的末尾添加文本 [英] Shell script to add text at the end of Directory and specific files
问题描述
我需要一些帮助编写Bash脚本。我已经尝试了很多,但无法弄清楚如何完成它,我是新来的节目。
我想创建一个脚本,将采取这应该是当前目录的子目录中的参数。
,然后找到该参数为一个文件或目录。
如果它是一个目录,它应该就在找到的目录名的 DDD 的。
的末尾添加扩展文本而如果是,它具有以下扩展名MPG或WMV或MOV'的文件,它应该在相同的扩展名的文件名末尾的文件扩展名的末尾添加。
示例:
如果该文件名为: hello.mov
,将被重命名为 hello.mov.mov
我的脚本:
#!/斌/庆典
在文件./$*
做
找到./$1 -maxdepth 1
如果[-d $文件] ?????????
科幻
对于AVI MPG MOV WMV EXT;
做
?????????????????
#!/斌/庆典
在./*#文件* /这个评论这里只是为了破镜重圆语法高亮
做
如果[[-d $文件]
然后
EXT = DDD
其他
EXT =$ {文件## *。}#得到扩展
科幻
MV$ {}文件$ {}文件。$分机#重命名文件$文件+。 + $分机
DONE
I need some help with writing a Bash script. I have tried a lot but can't figure out how to finish it and I am new to programming.
I want to create a script that will take a parameter that should be a sub-directory of the current directory.
And then find if the parameter is a file or directory.
If it is a directory it should just add the extension text at the end of the name of the found directory DDD.
And if it is a file that has the following extension 'mpg or wmv or mov', it should add at the end of the same extension as the file extension at the end of the file name.
Example:
If the file name is: hello.mov
, it will be renamed as hello.mov.mov
My Script:
#!/bin/bash
for file in ./$*
do
find ./$1 -maxdepth 1
if [ -d $file ]
?????????
fi
for ext in avi mpg wmv mov;
do
?????????????????
#!/bin/bash
for file in ./* # */ This comment here just to fix broken syntax highlighting
do
if [[ -d $file ]]
then
ext=DDD
else
ext="${file##*.}" # Get extension
fi
mv "${file}" "${file}.$ext" # Rename file to $file + . + $ext
done
这篇关于外壳脚本目录和特定文件的末尾添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!