微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

bash – 从文件中删除扩展名而不知道

我知道如何删除文件的扩展名,当我知道为:
nameis=$(basename $dataset .csv)

但是我想先删除任何扩展名,而不知道它是否知道如何做?

任何帮助赞赏,
摊晒

在bash中,您可以执行以下操作:
nameis=${dataset%.*}

…例如:

$ dataset=foo.txt
$ nameis=${dataset%.*}
$ echo $nameis
foo

这种语法在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.

原文地址:https://www.jb51.cc/bash/387640.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐