How to automatically remove the file extension in a file name

余生长醉 提交于 2019-12-02 02:11:30
 f=file.zip
 echo ${f%.zip}

 file

The '%' is a parameter modifier, it means, delete from the right side of the value of the variable whatever is after the '%' char, in this case, the string .zip. You can make this more general to remove any trailing extension, by using a wild card like

 echo ${f%.*}

 file

IHTH

If you want to remove the from the last period to the end, try this:

$ f=some.thing.zip
$ echo ${f%.*}
some.thing
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!