我刚开始在BASH中使用args,并且正在尝试编写脚本,在给定的标题上设置‘.MKV’标签来匹配它的文件名:去掉扩展名。命令..。
mkvpropedit "Good Life.mkv" --edit info --set "title=Good Life"...works没有问题,(感谢另一个回答的StackOverflow问题),我可以拉入完整的文件名-带有空格和扩展名-并可靠地将其拆分为完整的文件名(即"Good Life.mkv")和不带扩展名的文件名:即“美好生活”。完整的脚本(mkvRetitle.sh)是...
#!/bin/bash
echo "Change .MKV title to match its filename"
eval fileWhole=\${1}
eval fileTitle=$(echo "\${1%.*}")
# echo $fileWhole
# echo $fileTitle
mkvpropedit fileWhole --edit info --set "title=$fileTitle"然而,我的脚本中'mkvpropedit‘的实际调用是错误的。Passing a string with spaces as a function argument in bash返回Error: The file 'fileWhole' is not a Matroska file or it could not be found.我尝试过在mkvpropedit中找到的想法
但一直没有运气,也找不到其他看起来可能的东西:来自其他网站。我真的很感谢你的帮助。非常感谢。
发布于 2017-09-13 05:10:37
每当你必须处理包含空格的变量/参数时,只需用引号将其括起来,就是这样。
#!/bin/bash
echo "Change .MKV title to match its filename"
fileWhole="$1"
fileTitle="${1%.*}"
echo "$fileWhole"
echo "$fileTitle"
mkvpropedit "$fileWhole" --edit info --set "title=$fileTitle"https://stackoverflow.com/questions/46185167
复制相似问题