bash for循环中的文件名不带扩展名

在这样的for循环中:
for f in `ls *.avi`; do echo $f; ffmpeg -i $f $f.mp3; done

$ f将是完整的文件名,包括扩展名。例如,对于song1.avi,命令的输出将是song1.avi.mp3。有没有办法只有song1,没有。环境中的.avi?

我想象有办法使用awk或其他这样的工具,但我希望有一些更直接的东西。

谢谢

使用bash参数展开
${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.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...