简体   繁体   English

文件名参数扩展bash

[英]file name parameter expansion bash

I am trying to find all files with a specific extension and change them to a different extension. 我正在尝试查找具有特定扩展名的所有文件,并将其更改为其他扩展名。 Both extensions will be put in as command line arguments. 这两个扩展名都将作为命令行参数放入。 How would I set a variable equal to the file name before the "." 我如何将变量设置为等于“。”之前的文件名。 using parameter expansion? 使用参数扩展? I am new to scripting so any help would be greatly appreciated! 我是脚本新手,所以对您的帮助将不胜感激!

name=${param%.*}

will set name to the value of $param without the extension. name设置为$param的值,不带扩展名。

From the bash manual : 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. 如果模式参数的膨胀值的尾部匹配,则扩展的结果是用最短的匹配(“%”的情况下)或最长的匹配(即“%%”的情况下) 参数的值删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM