语法“ $ {foo ## *。}”如何获取文件扩展名?

xiaohan2012

为什么此命令可以成功检索文件扩展名?

file_ext=${filename##*.}
米查斯

看一下man bash(或您正在使用的任何shell):

   ${parameter##word}
          Remove matching prefix pattern.  The word is expanded to produce
          a pattern just as in pathname expansion.  If the pattern matches
          the  beginning of the 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 pat‐
          tern (the ``##'' case) deleted.  If parameter is  @  or  *,  the
          pattern  removal operation is applied to each positional parame‐
          ter in turn, and the expansion is the resultant list.  If param‐
          eter  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.

因此,在您的情况下,它将删除直到最后一个“”的所有内容。并返回剩下的字符串,该字符串恰好是文件的扩展名。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

包含foo和bar的文件的Ack语法

如何为Visual Studio 2010或2013的备用文件扩展名获取语法突出显示?

获取Visual Studio代码以语法突出显示无扩展名的文件作为bash脚本?

Intellij IDEA。检查没有扩展名的文件的语法

Adobe-Brackets,更改文件扩展名的默认语法

nginx位置通过文件扩展名语法拒绝

glob语法以匹配具有任何扩展名或没有扩展名的文件

如何在Sublime Text 3中为语法设置默认文件扩展名?

如何在Sublime Text 3中为特定语法设置保存文件的默认文件扩展名

.htaccess文件中“如果主机不是foo,则重定向到bar”的正确语法是什么?

语法的含义是什么:<element #foo />

bash中if [“ $ foo” ==“ bar”]的语法错误

Javascript语法:var array = [] .push(foo);

JavaScript语法foo:是什么意思?

Meld:将文件扩展名与语言语法突出显示相关联

双文件类型扩展名:Sublime Text 3中正确的语法突出显示

方法调用语法`foo.method()`和UFCS`Foo :: method(&foo)`有什么区别?

如何正确获取文件扩展名?

AngularJS如何获取文件扩展名

如何在vscode中正确插入语法扩展名(这样就可以了)?

Vim食谱中的次要语法突出显示扩展名

带有扩展名的泛型的正确Java语法

PostgreSQL-修改扩展名中的CREATE TABLE语法

防止foo =“ *”中的glob扩展;回声$ foo

获取文件扩展名

是否可以基于特定目录而不是文件扩展名创建语言标识符(用于语法突出显示)?

默认情况下,将语法高亮显示添加到VIM或GVIM的某些文件扩展名

这个语法是什么意思:const foo = () => {}

双括号“ [[foo()]]类型名称;”的含义 C ++中的语法?