qingmin兄的autuunzip脚本
时间:2007-11-14 来源:woshiliumang
#!/bin/bash
#
# Filename : autounzip
# Description: Uncompress files, and print "OK" out if the file
# can be uncompressed successfully.
# Author : Liu Qingmin
# Syntax : autounzip <target>
# Support : *.tar | *.zip | *.rar | *.tgz
# *.gz | *.bz2 | *.bz
# Handle Error Information
if [ $# != 1 ];then
echo "Usage:`basename $0`:*.tar|*.zip|*.tgz|*.gz|*.bz|*.bz2]"
exit 1
fi
# Assign the parameter to the Macro OPT
OPT=$1
# Uncompress files
case $OPT in
*.tar)
tar xvf $OPT && echo "OK"
;;
*.tar.Z)
tar zxvf $OPT && echo "OK"
;;
*.zip)
unzip $OPT && echo "OK"
;;
*.tgz)
tar zxvf $OPT && echo "OK"
;;
*.gz)
if echo $OPT | grep ".tar.gz" > /dev/null 2>&1; then
tar xvzf $OPT && echo "OK"
else
gunzip $OPT && echo "OK"
fi
;;
*.bz2)
if echo $OPT | grep ".tar.bz2" > /dev/null 2>&1; then
tar jxvf $OPT && echo "OK"
else
bunzip2 $OPT && echo "OK"
fi
;;
*.bz)
if echo $OPT | grep ".tar.bz" > /dev/null 2>&1; then
tar jxvf $OPT && echo "OK"
else
bunzip2 $OPT && echo "OK"
fi
;;
*)
echo "File $OPT cannot be uncompressed with autounzip"
;;
esac