Bash: 将文件名 0 – FILENAME.mkv 转换为 FILENAME.mkv?

huangapple go评论66阅读模式
英文:

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}
英文:

Using Perl's rename in one line:

rename 's/.*\s+//' ./*.{mkv,mp4,mp3,opus}

huangapple
  • 本文由 发表于 2023年3月4日 07:57:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75632799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定