改进版本的压缩和解压的shell脚本

改进版本的压缩和解压的shell脚本,原来的脚本是linuxsir上的同学写的。下面的是我改的
#!/bin/bash

if [ -d $1 ]; then

    if [ -z $2 ]

    then

        tar czvf $1.tar.gz $1

        echo this is a DIR

        exit 0;

    else

        if [ $2 = "-t" ] ; then

            tar czvf $1-$(date +%m-%d-%Y).tar.gz $1

            echo this is a DIR

            exit 0;

        fi 

    fi

fi

UNPACK=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

  # echo ${1##*.}

if [ ${1##*.} = zip ] ; then

     unzip $1

     UNPACK=$?

fi

if [ ${1##*.} = rar ] ; then

     rar x $1

     UNPACK=$?

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 [ $UNPACK = 0 ] ; then

echo Success!

else

echo Maybe it is not a package or the package is damaged?

fi



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值