#!/bin/sh # vim: set sw=4 ts=4 et: help() { cat <<HELP smartzip -- automatically find the compression type of a file and then uncompress it USAGE: smartzip file smartzip knows about: bzip2 gzip zip HELP exit 0 } error() { # print an error and exit echo "$1" exit 1 } # print help if no args given: [ -z "$1" ] && help [ -r "$1" ] || error "error: can not read file $1" # inputfile="$1" ftype=`file "$inputfile"` case "$ftype" in "$inputfile: Zip archive"*) unzip "$inputfile" ;; "$inputfile: gzip compressed"*) gunzip "$inputfile" ;; "$inputfile: bzip2 compressed"*) bunzip2 "$inputfile" ;; *) error "File $inputfile can not be uncompressed with smartzip";; esac #