1

I have temp.tar.gz in $1
How do I get just 'temp' in another variable ?

I am using bash.
Thanks in advance.

Nullpoet
  • 10,299
  • 16
  • 47
  • 62
  • 1
    Possible duplicate of http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash – axel_c Sep 03 '11 at 09:05

3 Answers3

6

Use bash parameter expansion:

echo ${1%%.*}
Mu Qiao
  • 6,683
  • 1
  • 29
  • 34
0

Using bash

echo ${string%%.*}
ghostdog74
  • 307,646
  • 55
  • 250
  • 337
0

Using bash and 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.

Alex Reynolds
  • 94,180
  • 52
  • 233
  • 338