Skip to content

Instantly share code, notes, and snippets.

@penryu
Created November 10, 2011 17:56
Show Gist options
  • Save penryu/1355575 to your computer and use it in GitHub Desktop.
Save penryu/1355575 to your computer and use it in GitHub Desktop.
#!/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
@penryu
Copy link
Author

penryu commented Nov 11, 2011

This was just an exercise for a lab at school.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment