for f in `ls *.avi`; do echo $f; ffmpeg -i $f $f.mp3; done
$ f将是完整的文件名,包括扩展名。例如,对于song1.avi,命令的输出将是song1.avi.mp3。有没有办法只有song1,没有。环境中的.avi?
我想象有办法使用awk或其他这样的工具,但我希望有一些更直接的东西。
谢谢
${f%%.*}
请注意,您需要贪婪版本,因为文件名中有多个点。
从bash手册:
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter,then the result of the expansion is the 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.