#!/bin/bash
#--------------------------------------
#本脚本实现根据文件的后缀名进行解压
#日期:2016/7/23
#作者:齐豪
#--------------------------------------
Usage(){
echo "usage: 2.self_compression.sh [--list] or [Source compressed file]"
echo " [Destination path]"
echo "Self compression accroding to the file name suffix"
exit
}
List(){ #提示支持的解压类型
echo "Supported file types: zip tar tar.gz tar.bz2"
exit
}
filename=$1 #要解压的文件
path=$2 #解压到路径名
ext="${filename##*.}" #获取文件名的后缀
if [ -z $filename ]; then #判断用户是否输入了第一参数
Usage;
elif [ $filename = '--list' ]; then #显示支持的解压类型
List;
elif [[ -n $filename && -n $path ]]; then #解压
case $ext in
'tar')
eval "tar xvf $filename -C $path";;
'gz')
eval "tar zxvf $filename -C $path";;
'bz2')
eval "tar jxvf $filename -C $path";;
'zip')
eval "unzip $filename -d $path";;
*)
echo 'error(101) This type is not supported(tar|gz|bz2|zip)';;
esac
echo "right"
fi
自动根据压缩文件的后缀名进行解压
最新推荐文章于 2024-09-10 06:00:00 发布