文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>shell编程----解压脚本

shell编程----解压脚本

时间:2006-10-22  来源:samuel1004

在linuxsir上看到一个关于解压的脚本,做了一些补充,应该有点实用了。再也不要记住那些选项了。

#!/bin/bash
# This scripts can unpack .bz2 .tar.bz2 .gz .tar.gz
# .tar .tar.Z .Z packages.
# The author is Guo R.H.

USAGE="Usage:`basename $0` [one package]"
UNPACK=1

[ $# -ne 1 ] && echo $USAGE && exit 1

if [ ${1##*.} = bz2 ] ; then
        TEMP=${1%.*}
        if [ ${TEMP##*.} = tar ] ; then
                tar jxvf $1
                UNPACK=$?
                echo 'This is a "tar.bz2" package'
        else
                bunzip2 $1
                UNPACK=$?
                echo 'This is a bz2 package'
        fi
fi

if [ ${1##*.} = gz ] ; then
        TEMP=${1%.*}
        if [ ${TEMP##*.} = tar ] ; then
                tar zxvf $1
                UNPACK=$?
                echo 'This is a "tar.gz" package'
        else
                gunzip $1
                UNPACK=$?
                echo "This is a gz package"
        fi
fi

if [ ${1##*.} = tar ] ; then
        tar xvf $1
        UNPACK=$?
        echo 'This is a "tar" package'
fi

if [ ${1##*.} = Z ] ; then
        TEMP=${1%.*}
        if [ ${TEMP##*.} = tar ] ; then
               tar vxZf $1
               UNPACK=$?
               echo 'This is a "tar.Z" package'
        else
               uncompress $1
               UNPACK=$?
               echo "This is a .Z package"
        fi
fi

if [ ${1##*.} = tgz ] ; then
        tar zxvf $1
        UNPACK=$?
        echo "This is a tgz package"
fi

if [ $UNPACK = 0 ] ; then
        echo "Success!"
else
        echo "Maybe it is not a package or the package is damaged?"
fi
exit 0
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载