简体   繁体   English

如何在bash shell脚本中删除文件扩展名?

[英]How to remove file extention in bash shell scripting?

I have temp.tar.gz in $1 我的temp.tar.gz中有$ 1
How do I get just 'temp' in another variable ? 如何在另一个变量中获得“临时”值?

I am using bash. 我正在使用bash。
Thanks in advance. 提前致谢。

使用bash参数扩展

echo ${1%%.*}

使用bash

echo ${string%%.*}

Using bash and GNU parallel : 使用bash和GNU parallel

$ myFilename=`find . -maxdepth 1 -name *.gz -print0 | parallel -0 echo {.} | parallel -0 echo {.}`
$ echo $myFilename
./temp

Not as clean as the other approaches, for sure, but it will work with filenames with spaces in them. 当然,它不像其他方法那样干净,但是它可以使用带有空格的文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM