Shell 自定义解压

 

Linux:  Red Hat Enterprise Linux 5

 

写了一个名为 smartzip.sh 的脚本,该脚本可以自动解压bzip2, gzip和zip 类型的压缩文件:

 

smartzip.sh

 

#!/bin/bash

ftype="$(file "$1")"
case "$ftype" in
"$1: Zip archive"*)
    unzip "$1" ;;
"$1: gzip compressed"*)
    gunzip "$1" ;;
"$1: bzip2 compressed"*)
    bunzip2 "$1" ;;
*) echo "File $1 can not be uncompressed with smartzip";;
esac

 

给 smartzip.sh 赋予执行的权限:

chmod +x smartzip.sh

 在同一目录下,有个文件 articles.zip

也赋予该文件执行的权限

chmod +x articles.zip

 

使用命令 smartzip 解压文件

./smartzip.sh articles.zip

 

$1 就是字符串 articles.zip

 

执行结果:



 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值