Stripping Extensions with bash

Michael Kipper mkipper at
Wed Jan 7 17:45:56 PST 2004


Slightly off topic, but:
I have some scripts that I use to install some BLFS stuff after I use nALFS 
to install LFS 5.0.
I have written some rudimentary functions to try and streamline it, like a 
decompress() function, which will untar a file into /usr/src
But I'm new to bash, so if someone will help me translate this pseudocode 
to bash script, that would be great:

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 


Michael Kipper
Toronto, Ontario

More information about the alfs-discuss mailing list