Stripping off extensions for decompress() function

From: Michael Kipper (mkipper_at_rogers.com)
Date: 01/08/04


Date: Thu, 08 Jan 2004 01:52:29 GMT

Hello,

I am trying to write a decompress() function, which will untar a file into
/usr/src, regardless of the archive type
I'm new to bash, so if someone will help me translate this pseudocode
to bash script, that would be great:

decompress()
{
extension=`somefunction $1`
if (extension == "tar.gz") then
            tar -zxf filename
else if (extension == "tar.bz2") then
            tar -jxf filename
else if (extension == "bz2") then
            bunzip2 filename
else if (extension == "gz") then
            gunzip filename
}

There must be some function to do this properly, like `basename` or
something like it. Also, if there's a better way to do this, by all
means...

Thanks,

Michael Kipper
Toronto, Ontario



Relevant Pages

  • Re: Newbie wants a simple script in perl
    ... The script reads the list - for each name in the list, it will perform an operation (an executable of a "C-program" and writes to same name with a different extension, say ".mp3". ... I changed it to bash but the code didn't work ... CONV2 takes CONV.out as well as the final output file. ...
    (comp.lang.perl.misc)
  • Re: Download Manager Query
    ... add a "" to the end of the filename and before any extension. ... good, I think, but you can no longer operate on the file, rename it or ... execute it. ... The problem is that '(' is a special character for bash. ...
    (Ubuntu)
  • Re: script encoding - slightly OT
    ... popular zip programs to decompress ... the files probably by changing the extension of the file from .js to ... JS script to GZ, opened it in Power Archiver, ...
    (microsoft.public.scripting.wsh)
  • Re: Treatment of extension column changed in SP4?
    ... The file extension column is populated with ".doc.gz" etc. and the ... manages to decompress the file, but of course when passing the ... suitable filter, it fails with a 0x80070057 error. ... Is the IFilter system smart enough to find the right ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Opening a zip file
    ... goto www.winzip.com to decompress your file ... Frank Kabel ... Keith wrote: ... > I have received a file with a zip extension. ...
    (microsoft.public.excel.newusers)