开发者

in shell script,how to get file name after untar the file

开发者 https://www.devze.com 2023-03-08 08:50 出处:网络
i am having tar file \"test.tar.gz\'.now i want to get the n开发者_JS百科ame \"test\' after untar the \"test.tar.gz\'. In shell script ,how to get this.To strip an extension from a file name, use base

i am having tar file "test.tar.gz'.now i want to get the n开发者_JS百科ame "test' after untar the "test.tar.gz'. In shell script ,how to get this.


To strip an extension from a file name, use basename:

basename test.tar.gz .tar.gz

prints test

But that is just the base name of the archive. It's not always the name of any file or directory which the tar creates. The tar archive can contain any file names. If you need those, use tar tf to list the content of the archive.


Use something like:

file="test.tar.gz"
tarfilename=${file%.tar.gz}

read up about it man bash search for variable expansion.

0

精彩评论

暂无评论...
验证码 换一张
取 消