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
执行结果:

相关推荐
laisean 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
JohnYork 2020-10-16
Julyth 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
wangzhaotongalex 2020-09-22
流年浅滩 2020-10-23
liujianhua 2020-10-22
woaimeinuo 2020-10-21
laisean 2020-09-01
vvu 2020-09-16
libao 2020-09-16
Yyqingmofeige 2020-08-18
zhushixia 2020-08-17