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,949
  • 20
  • 48
  • 65
  • 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,941
  • 1
  • 31
  • 34
0

Using bash

echo ${string%%.*}
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
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
  • 95,983
  • 54
  • 240
  • 345