英文:
Bash: Converting Filename 0 - FILENAME.mkv to FILENAME.mkv?
问题
我试图将一些形式为0 - FILENAME.mkv
的文件转换为FILENAME.mkv
,但我在做某些微妙的错误。此子程序位于我的Manjaro OS计算机的主文件夹中的.bashrc文件中。每当我更新它时,所在的shell会执行source .bashrc
以确保它是最新的。
然而,输出为空字符串""
,但在shell中独立执行时可以正常运行。
我做错了什么?
英文:
I'm trying to convert a few files of the form 0 - FILENAME.mkv
to FILENAME.mkv
, but I'm doing something subtly wrong. This subroutine is in the .bashrc file in my home folder on my Manjaro OS computer. Whenever I update it, the shell it gets executed from does a source .bashrc
to ensure that it is up to date.
However, the output is empty ""
, but runs properly when executed stand-alone in the shell.
What am I doing wrong?
Convert_Filenames_Remove_Leading_Number_Prefix() {
ConversionTemporary="/run/media/sarah/MSS_EXtended/Conversion Temporary"
TemporaryDir="/tmp/T1"
mkdir "$ConversionTemporary"
mkdir "$TemporaryDir"
echo "Convert_Filenames_Remove_Leading_Number_Prefix()"
echo "NOTES: Currently Works on .mp4, .mp3, opus, and .mkv files only. Converts: 0 - FILENAME.EXT -> FILENAME.EXT\n"
#Copy to conversion temporary for safekeeping
cp -a "`pwd`" "$ConversionTemporary"
echo "Copying files to ConversionTemporary complete"
#Main Sequence
for i in *.{mkv,mp4,mp3,opus}; do
filaname=$(echo "$i" | cut -d "-" -f2 | awk '{$1=$1};1')
echo "Result: $filename"
mv -v "$i" "$filename"
done
}
答案1
得分: 1
使用Perl的rename
在一行中执行:
rename 's/.*\s+//' ./*.{mkv,mp4,mp3,opus}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论