Skip to content

Instantly share code, notes, and snippets.

@huzhifeng
Created June 6, 2014 03:14
Show Gist options
  • Save huzhifeng/0a42a538fee47b0abe65 to your computer and use it in GitHub Desktop.
Save huzhifeng/0a42a538fee47b0abe65 to your computer and use it in GitHub Desktop.
Smart uncompress
#!/bin/bash
smart_uncompress()
{
if [ $# -lt 1 ]; then
echo "At least one paramater required"
exit 1
fi
ftype="$(file $1)"
case ${ftype} in
"$1: Zip archive"*)
unzip $1 ;;
"$1: gzip compressed"*)
tar -xzf $1 ;;
"$1: bzip2 compressed"*)
tar -xjf $1 ;;
*)
echo "File $1 can not be uncompressed with smartzip" ;;
esac
}
smart_uncompress $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment