问题描述
我试图让在bash脚本,需要从文件名中去除文件扩展名,如以下
原文:something.zip
删除版本:什么
和我想我可以用削减这一点,但我担心的情况可能会出现在有可能是有一个以上的周期,等文件名,类似于以下的东西。
something.v2.zip
话说回来,我想知道如果任何人有任何建议,以什么我所能做的只是删除最后一个周期,并从一行文本/文件名后面的文本?任何帮助将是AP preciated,谢谢!
F = file.zip
回声$ {F%.zip文件} 文件
的'%'是一个参数调节剂,这意味着,从可变无论是%炭后的值的右侧删除,在这种情况下,串的.zip
。你可以让这个更一般的,以消除任何尾随的扩展,使用通配符像
回声$ {F%。*} 文件
IHTH
I am trying to make a script in bash that requires the removal of the the file extension from a file name, like the following
original: something.zip
removed version: something
And I was thinking I could use cut for this, but I am worried that a situation could arise where there might be a file name that has more than one period, etc, something similar to the following
something.v2.zip
having said that, I was wondering if anyone had any recommendations as to what I could do to just remove the last period and the text after it from a line of text/filename? any help would be appreciated, thanks!
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
这篇关于我怎么能自动删除的文件名的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!