Created
November 10, 2011 17:56
-
-
Save penryu/1355575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# decomp - decompress arbitrary archives by extension | |
# author: Tim Hammerquist <penryu@gmail.com> | |
UNZIP=`which unzip` | |
TAR=`which tar` | |
extract_zip="$UNZIP" | |
extract_tgz="$TAR zxf" | |
extract_tbz="$TAR jxf" | |
extract_tar="$TAR xf" | |
archive=$1 | |
case "$archive" in | |
*.zip) $extract_zip $archive ;; | |
*.tar.gz | *.tgz ) $extract_tgz $archive ;; | |
*.tar.bz2 | *.tbz2 ) $extract_tbz $archive ;; | |
*.tar) $extract_tar $archive ;; | |
*) | |
if [[ "$archive" =~ \.((tar\.)?([^.]+))$ ]]; then | |
ext=${BASH_REMATCH[1]} | |
echo "Can't determine archive type for extension '$ext'." | |
else | |
echo "Can't determine file type for '$archive'." | |
fi | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was just an exercise for a lab at school.