Skip to content

Instantly share code, notes, and snippets.

@recall704
Created June 13, 2019 07:25
Show Gist options
  • Save recall704/02a5d1c9c852698c31abb6adde53ed40 to your computer and use it in GitHub Desktop.
Save recall704/02a5d1c9c852698c31abb6adde53ed40 to your computer and use it in GitHub Desktop.
auto uncompression file
#!/bin/bash
Usage(){
echo "usage: e.sh [--list] or [Source compressed file]"
echo " [Destination path]"
echo "Self uncompression accroding to the file name suffix"
echo " "
echo "eg. e.sh docker-18.06.tgz /path/to/data"
exit
}
#提示支持的解压类型
List(){
echo "Supported file types: zip tar tar.gz tgz 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";;
'tgz')
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 "done"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment