Shell自定义解压
Shell自定义解压
Shell自定义解压
Linux: Red Hat Enterprise Linux 5
写了一个名为 smartzip.sh 的脚本,该脚本可以自动解压bzip2, gzip和zip 类型的压缩文件:
smartzip.sh
Js代码
#!/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 赋予执行的权限:
Js代码
chmod +x smartzip.sh
在同一目录下,有个文件 articles.zip
也赋予该文件执行的权限
Js代码
chmod +x articles.zip
使用命令 smartzip 解压文件
Js代码
./smartzip.sh articles.zip
$1 就是字符串 articles.zip
执行结果:
评论暂时关闭