Stripping Extensions with bash

Kevin P. Fleming kpfleming at linuxfromscratch.org
Wed Jan 7 19:12:13 PST 2004


Michael Kipper wrote:

 > 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...

You don't need to extract the extension into a separate variable... 
something like this will work:

case $filename in
   *.tar.gz)
   *.tgz)
     tar xzvf $filename
     ;;
   *.tar.bz2)
     tar xjvf $filename
     ;;
    *.tar)
     tar xvf $filename
     ;;
    *.gz)
      gunzip $filename
      ;;
    *.bz2)
      bunzip2 $filename
      ;;
esac

(untested so it may contain syntax errors)




More information about the alfs-discuss mailing list