如果你正在使用bash
${f%%.mp4}
将给出没有.mp4扩展名的文件名.
尝试使用它像这样:
for f in *.mp4; do
ffmpeg -i "$f" -f mp3 -ab 192000 -vn "mp3s/${f%%.mp4}.mp3"
done
…并且不要忘记给出的示例中的do关键字.
说明
bash手册(man bash)声明:
${parameter%word} ${parameter%%word}
Remove matching suffix pattern.
The word is expanded to produce
a pattern just as in pathname expansion. If the pattern matches
a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with
the shortest matching pattern (the %'' case) or the longest
matching pattern (the%%” case) deleted. If parameter is @
or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant
list. If parameter is an array variable subscripted with @ or
*, the pattern removal operation is applied to each member of
the array in turn, and the expansion is the resultant list.
这只是您可以对shell变量执行的许多字符串操作之一.它们都以参数扩展名称命名.
这也是bash手册中给出的章节标签.因此man bash / paramter exp应该快速带你到那里.`